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: [
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,
),
],
),
),

View file

@ -6,50 +6,94 @@ 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(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (showTitle)
const Padding(
padding: EdgeInsets.only(bottom: 8),
child: SectionRow('Location'),
),
ImageMap(
markerId: entry.path,
latLng: LatLng(
entry.latLng.item1,
entry.latLng.item2,
),
geoUri: entry.geoUri,
initialZoom: settings.infoMapZoom,
),
if (entry.isLocated)
Padding(
padding: const EdgeInsets.only(top: 8),
child: InfoRow('Address', entry.addressDetails.addressLine),
),
],
);
final showMap = (_loadedUri == entry.uri) || (entry.hasGps && widget.visibleNotifier.value);
if (showMap) {
_loadedUri = entry.uri;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (widget.showTitle)
const Padding(
padding: EdgeInsets.only(bottom: 8),
child: SectionRow('Location'),
),
ImageMap(
markerId: entry.path,
latLng: LatLng(
entry.latLng.item1,
entry.latLng.item2,
),
geoUri: entry.geoUri,
initialZoom: settings.infoMapZoom,
),
if (entry.isLocated)
Padding(
padding: const EdgeInsets.only(top: 8),
child: InfoRow('Address', entry.addressDetails.addressLine),
),
],
);
} else {
_loadedUri = null;
return const SizedBox.shrink();
}
}
void _handleChange() => setState(() {});
}
class ImageMap extends StatefulWidget {

View file

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