info: improved location section build
This commit is contained in:
parent
8b31e3ee97
commit
7d212e08ed
3 changed files with 91 additions and 37 deletions
|
@ -80,7 +80,13 @@ class InfoPageState extends State<InfoPage> {
|
|||
children: [
|
||||
Expanded(child: BasicSection(entry: entry)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: LocationSection(entry: entry, showTitle: false)),
|
||||
Expanded(
|
||||
child: LocationSection(
|
||||
entry: entry,
|
||||
showTitle: false,
|
||||
visibleNotifier: widget.visibleNotifier,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -92,7 +98,11 @@ class InfoPageState extends State<InfoPage> {
|
|||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
BasicSection(entry: entry),
|
||||
LocationSection(entry: entry, showTitle: true),
|
||||
LocationSection(
|
||||
entry: entry,
|
||||
showTitle: true,
|
||||
visibleNotifier: widget.visibleNotifier,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -6,29 +6,67 @@ import 'package:flutter/material.dart';
|
|||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:outline_material_icons/outline_material_icons.dart';
|
||||
|
||||
class LocationSection extends AnimatedWidget {
|
||||
class LocationSection extends StatefulWidget {
|
||||
final ImageEntry entry;
|
||||
final bool showTitle;
|
||||
final ValueNotifier<bool> visibleNotifier;
|
||||
|
||||
LocationSection({
|
||||
const LocationSection({
|
||||
Key key,
|
||||
@required this.entry,
|
||||
@required this.showTitle,
|
||||
}) : super(
|
||||
key: key,
|
||||
listenable: Listenable.merge([
|
||||
entry.metadataChangeNotifier,
|
||||
entry.addressChangeNotifier,
|
||||
]));
|
||||
@required this.visibleNotifier,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_LocationSectionState createState() => _LocationSectionState();
|
||||
}
|
||||
|
||||
class _LocationSectionState extends State<LocationSection> {
|
||||
String _loadedUri;
|
||||
|
||||
ImageEntry get entry => widget.entry;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_registerWidget(widget);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(LocationSection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_unregisterWidget(oldWidget);
|
||||
_registerWidget(widget);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_unregisterWidget(widget);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _registerWidget(LocationSection widget) {
|
||||
entry.metadataChangeNotifier.addListener(_handleChange);
|
||||
entry.addressChangeNotifier.addListener(_handleChange);
|
||||
widget.visibleNotifier.addListener(_handleChange);
|
||||
}
|
||||
|
||||
void _unregisterWidget(LocationSection widget) {
|
||||
entry.metadataChangeNotifier.removeListener(_handleChange);
|
||||
entry.addressChangeNotifier.removeListener(_handleChange);
|
||||
widget.visibleNotifier.removeListener(_handleChange);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return !entry.hasGps
|
||||
? const SizedBox.shrink()
|
||||
: Column(
|
||||
final showMap = (_loadedUri == entry.uri) || (entry.hasGps && widget.visibleNotifier.value);
|
||||
if (showMap) {
|
||||
_loadedUri = entry.uri;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (showTitle)
|
||||
if (widget.showTitle)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 8),
|
||||
child: SectionRow('Location'),
|
||||
|
@ -49,7 +87,13 @@ class LocationSection extends AnimatedWidget {
|
|||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
_loadedUri = null;
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
void _handleChange() => setState(() {});
|
||||
}
|
||||
|
||||
class ImageMap extends StatefulWidget {
|
||||
|
|
|
@ -17,7 +17,7 @@ class MetadataSectionSliver extends StatefulWidget {
|
|||
const MetadataSectionSliver({
|
||||
@required this.entry,
|
||||
@required this.columnCount,
|
||||
this.visibleNotifier,
|
||||
@required this.visibleNotifier,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue