From 65b6c9b355e8b924c5a0cb08b2331f8563baa4cf Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Tue, 22 Sep 2020 16:34:48 +0900 Subject: [PATCH] settings: added coordinate format example --- lib/utils/constants.dart | 3 ++ lib/widgets/common/aves_selection_dialog.dart | 46 ++++++++++++------- lib/widgets/settings/settings_page.dart | 6 +++ 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index 65479a6f6..742466b3b 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; +import 'package:tuple/tuple.dart'; class Constants { // as of Flutter v1.11.0, overflowing `Text` miscalculates height and some text (e.g. 'Å') is clipped @@ -17,6 +18,8 @@ class Constants { offset: Offset(0.5, 1.0), ); + static const pointNemo = Tuple2(-48.876667, -123.393333); + static const List androidDependencies = [ Dependency( name: 'CWAC-Document', diff --git a/lib/widgets/common/aves_selection_dialog.dart b/lib/widgets/common/aves_selection_dialog.dart index a681e8df7..a8c121f82 100644 --- a/lib/widgets/common/aves_selection_dialog.dart +++ b/lib/widgets/common/aves_selection_dialog.dart @@ -3,14 +3,18 @@ import 'package:flutter/widgets.dart'; import 'aves_dialog.dart'; +typedef TextBuilder = String Function(T value); + class AvesSelectionDialog extends StatefulWidget { final T initialValue; final Map options; + final TextBuilder optionSubtitleBuilder; final String title; const AvesSelectionDialog({ @required this.initialValue, @required this.options, + this.optionSubtitleBuilder, @required this.title, }); @@ -41,20 +45,30 @@ class _AvesSelectionDialogState extends State { ); } - Widget _buildRadioListTile(T value, String title) => RadioListTile( - key: Key(value.toString()), - value: value, - groupValue: _selectedValue, - onChanged: (v) { - _selectedValue = v; - Navigator.pop(context, _selectedValue); - setState(() {}); - }, - title: Text( - title, - softWrap: false, - overflow: TextOverflow.fade, - maxLines: 1, - ), - ); + Widget _buildRadioListTile(T value, String title) { + return RadioListTile( + key: Key(value.toString()), + value: value, + groupValue: _selectedValue, + onChanged: (v) { + _selectedValue = v; + Navigator.pop(context, _selectedValue); + setState(() {}); + }, + title: Text( + title, + softWrap: false, + overflow: TextOverflow.fade, + maxLines: 1, + ), + subtitle: widget.optionSubtitleBuilder != null + ? Text( + widget.optionSubtitleBuilder(value), + softWrap: false, + overflow: TextOverflow.fade, + maxLines: 1, + ) + : null, + ); + } } diff --git a/lib/widgets/settings/settings_page.dart b/lib/widgets/settings/settings_page.dart index 15f7bdbc0..f7d85ab9d 100644 --- a/lib/widgets/settings/settings_page.dart +++ b/lib/widgets/settings/settings_page.dart @@ -2,6 +2,7 @@ import 'package:aves/model/settings/coordinate_format.dart'; import 'package:aves/model/settings/home_page.dart'; import 'package:aves/model/settings/screen_on.dart'; import 'package:aves/model/settings/settings.dart'; +import 'package:aves/utils/constants.dart'; import 'package:aves/widgets/common/aves_selection_dialog.dart'; import 'package:aves/widgets/common/data_providers/media_query_data_provider.dart'; import 'package:aves/widgets/common/highlight_title.dart'; @@ -80,6 +81,11 @@ class SettingsPage extends StatelessWidget { builder: (context) => AvesSelectionDialog( initialValue: settings.coordinateFormat, options: Map.fromEntries(CoordinateFormat.values.map((v) => MapEntry(v, v.name))), + optionSubtitleBuilder: (dynamic value) { + // dynamic declaration followed by cast, as workaround for generics limitation + final formatter = (value as CoordinateFormat); + return formatter.format(Constants.pointNemo); + }, title: 'Coordinate Format', ), );