info: improved location section build

This commit is contained in:
Thibault Deckers 2020-01-20 10:11:58 +09:00
parent 8b31e3ee97
commit 7d212e08ed
3 changed files with 91 additions and 37 deletions

View file

@ -80,7 +80,13 @@ class InfoPageState extends State<InfoPage> {
children: [ children: [
Expanded(child: BasicSection(entry: entry)), Expanded(child: BasicSection(entry: entry)),
const SizedBox(width: 8), 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( delegate: SliverChildListDelegate(
[ [
BasicSection(entry: entry), BasicSection(entry: entry),
LocationSection(entry: entry, showTitle: true), LocationSection(
entry: entry,
showTitle: true,
visibleNotifier: widget.visibleNotifier,
),
], ],
), ),
), ),

View file

@ -6,29 +6,67 @@ import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:outline_material_icons/outline_material_icons.dart'; import 'package:outline_material_icons/outline_material_icons.dart';
class LocationSection extends AnimatedWidget { class LocationSection extends StatefulWidget {
final ImageEntry entry; final ImageEntry entry;
final bool showTitle; final bool showTitle;
final ValueNotifier<bool> visibleNotifier;
LocationSection({ const LocationSection({
Key key, Key key,
@required this.entry, @required this.entry,
@required this.showTitle, @required this.showTitle,
}) : super( @required this.visibleNotifier,
key: key, }) : super(key: key);
listenable: Listenable.merge([
entry.metadataChangeNotifier, @override
entry.addressChangeNotifier, _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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return !entry.hasGps final showMap = (_loadedUri == entry.uri) || (entry.hasGps && widget.visibleNotifier.value);
? const SizedBox.shrink() if (showMap) {
: Column( _loadedUri = entry.uri;
return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if (showTitle) if (widget.showTitle)
const Padding( const Padding(
padding: EdgeInsets.only(bottom: 8), padding: EdgeInsets.only(bottom: 8),
child: SectionRow('Location'), child: SectionRow('Location'),
@ -49,9 +87,15 @@ class LocationSection extends AnimatedWidget {
), ),
], ],
); );
} else {
_loadedUri = null;
return const SizedBox.shrink();
} }
} }
void _handleChange() => setState(() {});
}
class ImageMap extends StatefulWidget { class ImageMap extends StatefulWidget {
final String markerId; final String markerId;
final LatLng latLng; final LatLng latLng;

View file

@ -17,7 +17,7 @@ class MetadataSectionSliver extends StatefulWidget {
const MetadataSectionSliver({ const MetadataSectionSliver({
@required this.entry, @required this.entry,
@required this.columnCount, @required this.columnCount,
this.visibleNotifier, @required this.visibleNotifier,
}); });
@override @override