settings: added coordinate format example

This commit is contained in:
Thibault Deckers 2020-09-22 16:34:48 +09:00
parent 01b148139b
commit 65b6c9b355
3 changed files with 39 additions and 16 deletions

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:tuple/tuple.dart';
class Constants { class Constants {
// as of Flutter v1.11.0, overflowing `Text` miscalculates height and some text (e.g. 'Å') is clipped // 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), offset: Offset(0.5, 1.0),
); );
static const pointNemo = Tuple2(-48.876667, -123.393333);
static const List<Dependency> androidDependencies = [ static const List<Dependency> androidDependencies = [
Dependency( Dependency(
name: 'CWAC-Document', name: 'CWAC-Document',

View file

@ -3,14 +3,18 @@ import 'package:flutter/widgets.dart';
import 'aves_dialog.dart'; import 'aves_dialog.dart';
typedef TextBuilder<T> = String Function(T value);
class AvesSelectionDialog<T> extends StatefulWidget { class AvesSelectionDialog<T> extends StatefulWidget {
final T initialValue; final T initialValue;
final Map<T, String> options; final Map<T, String> options;
final TextBuilder<T> optionSubtitleBuilder;
final String title; final String title;
const AvesSelectionDialog({ const AvesSelectionDialog({
@required this.initialValue, @required this.initialValue,
@required this.options, @required this.options,
this.optionSubtitleBuilder,
@required this.title, @required this.title,
}); });
@ -41,20 +45,30 @@ class _AvesSelectionDialogState<T> extends State<AvesSelectionDialog> {
); );
} }
Widget _buildRadioListTile(T value, String title) => RadioListTile<T>( Widget _buildRadioListTile(T value, String title) {
key: Key(value.toString()), return RadioListTile<T>(
value: value, key: Key(value.toString()),
groupValue: _selectedValue, value: value,
onChanged: (v) { groupValue: _selectedValue,
_selectedValue = v; onChanged: (v) {
Navigator.pop(context, _selectedValue); _selectedValue = v;
setState(() {}); Navigator.pop(context, _selectedValue);
}, setState(() {});
title: Text( },
title, title: Text(
softWrap: false, title,
overflow: TextOverflow.fade, softWrap: false,
maxLines: 1, overflow: TextOverflow.fade,
), maxLines: 1,
); ),
subtitle: widget.optionSubtitleBuilder != null
? Text(
widget.optionSubtitleBuilder(value),
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
)
: null,
);
}
} }

View file

@ -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/home_page.dart';
import 'package:aves/model/settings/screen_on.dart'; import 'package:aves/model/settings/screen_on.dart';
import 'package:aves/model/settings/settings.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/aves_selection_dialog.dart';
import 'package:aves/widgets/common/data_providers/media_query_data_provider.dart'; import 'package:aves/widgets/common/data_providers/media_query_data_provider.dart';
import 'package:aves/widgets/common/highlight_title.dart'; import 'package:aves/widgets/common/highlight_title.dart';
@ -80,6 +81,11 @@ class SettingsPage extends StatelessWidget {
builder: (context) => AvesSelectionDialog<CoordinateFormat>( builder: (context) => AvesSelectionDialog<CoordinateFormat>(
initialValue: settings.coordinateFormat, initialValue: settings.coordinateFormat,
options: Map.fromEntries(CoordinateFormat.values.map((v) => MapEntry(v, v.name))), 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', title: 'Coordinate Format',
), ),
); );