2020-05-01 18:52:24 +00:00
|
|
|
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2021-12-28 14:23:08 +00:00
|
|
|
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
2020-05-01 18:52:24 +00:00
|
|
|
|
|
|
|
/// Multiple choices settings tile
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class MultiChoicesSettingsTile<T> extends SettingsTile {
|
|
|
|
final String title;
|
|
|
|
final List<MultiChoiceEntry<T>> choices;
|
|
|
|
final T currentValue;
|
|
|
|
final Function(T) onChanged;
|
2022-03-10 18:39:57 +00:00
|
|
|
final Widget? leading;
|
|
|
|
final Widget? trailing;
|
2020-05-01 18:52:24 +00:00
|
|
|
|
2021-12-28 14:23:08 +00:00
|
|
|
MultiChoicesSettingsTile({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.title,
|
|
|
|
required this.choices,
|
|
|
|
required this.currentValue,
|
|
|
|
required this.onChanged,
|
2021-04-06 15:40:13 +00:00
|
|
|
this.leading,
|
|
|
|
this.trailing,
|
2022-03-11 15:40:56 +00:00
|
|
|
}) : assert(currentValue != null);
|
2020-05-01 18:52:24 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SettingsTile(
|
2021-04-06 15:40:13 +00:00
|
|
|
leading: leading,
|
|
|
|
trailing: trailing,
|
2020-05-01 18:52:24 +00:00
|
|
|
title: title,
|
|
|
|
subtitle: choices.firstWhere((f) => f.id == currentValue).title,
|
2021-02-07 16:09:08 +00:00
|
|
|
onPressed: (_) => _changeValue(context),
|
2020-05-01 18:52:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// When the user request to change the current value
|
|
|
|
void _changeValue(BuildContext context) async {
|
|
|
|
final newChoice = await showMultiChoicesDialog(
|
|
|
|
context: context,
|
|
|
|
choices: choices,
|
|
|
|
defaultChoice: currentValue,
|
|
|
|
title: title,
|
|
|
|
);
|
|
|
|
if (newChoice == null) return;
|
|
|
|
onChanged(newChoice);
|
|
|
|
}
|
|
|
|
}
|