-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: The model selection interface supports grouping and disabling f…
…unctions
- Loading branch information
Showing
7 changed files
with
213 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
lib/components/settings/grouped_bottom_sheet_switcher.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:geek_chat/controller/settings.dart'; | ||
import 'package:geek_chat/models/bottom_switcher_model.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:logger/logger.dart'; | ||
|
||
// ignore: must_be_immutable | ||
class GroupedBottomSheetSwitcherComponent extends StatelessWidget { | ||
GroupedBottomSheetSwitcherComponent( | ||
{super.key, | ||
required this.title, | ||
required this.subTitle, | ||
required this.selectedValue, | ||
required this.options, | ||
required this.leadingIcon, | ||
required this.onTapCallback}); | ||
|
||
String title; | ||
String subTitle; | ||
String selectedValue; | ||
Logger logger = Get.find(); | ||
// List<Map<String, String>> options; | ||
List<GroupedBottomSwitcherOption> options; | ||
Function onTapCallback; | ||
IconData leadingIcon; | ||
|
||
List<Widget> buildOptionsList(BuildContext context) { | ||
List<Widget> widgets = []; | ||
widgets.add(ListTile( | ||
dense: true, | ||
title: Text( | ||
title.tr, | ||
style: const TextStyle(fontWeight: FontWeight.bold), | ||
), | ||
tileColor: Theme.of(context).scaffoldBackgroundColor, | ||
)); | ||
for (GroupedBottomSwitcherOption group in options) { | ||
widgets.add(ListTile( | ||
dense: true, | ||
title: Text(group.groupName), | ||
)); | ||
for (BottomSwitcherOption option in group.options) { | ||
if (option.disabled) { | ||
widgets.add(ListTile( | ||
title: Row( | ||
children: [ | ||
Radio( | ||
value: option.id, | ||
groupValue: selectedValue, | ||
onChanged: null, | ||
), | ||
Text( | ||
option.name.tr, | ||
), | ||
], | ||
), | ||
)); | ||
} else { | ||
widgets.add(ListTile( | ||
title: Row( | ||
children: [ | ||
Radio( | ||
value: option.id, | ||
groupValue: selectedValue, | ||
onChanged: (value) { | ||
onTapCallback(value); | ||
Navigator.pop(context); | ||
}, | ||
), | ||
Text( | ||
option.name.tr, | ||
), | ||
], | ||
), | ||
onTap: () { | ||
/// | ||
onTapCallback(option.id); | ||
Navigator.pop(context); | ||
}, | ||
)); | ||
} | ||
} | ||
} | ||
|
||
widgets.add(Container( | ||
padding: const EdgeInsets.only(top: 20), | ||
)); | ||
return widgets; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
logger.d("options: $options"); | ||
return GetBuilder<SettingsController>(builder: ((controller) { | ||
return ListTile( | ||
title: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text(title.tr), | ||
Text( | ||
subTitle.tr, | ||
style: const TextStyle(fontSize: 12), | ||
) | ||
], | ||
), | ||
leading: Icon(leadingIcon), | ||
trailing: const Icon(Icons.chevron_right_outlined), | ||
onTap: () { | ||
showModalBottomSheet( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(5.0)), | ||
context: context, | ||
builder: (context) { | ||
return SafeArea( | ||
child: Wrap( | ||
children: buildOptionsList(context), | ||
)); | ||
}); | ||
}, | ||
); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class BottomSwitcherOption { | ||
BottomSwitcherOption({ | ||
required this.id, | ||
required this.name, | ||
required this.additionalText, | ||
required this.disabled, | ||
}); | ||
String id; | ||
String name; | ||
String additionalText; | ||
bool disabled; | ||
} | ||
|
||
class GroupedBottomSwitcherOption { | ||
GroupedBottomSwitcherOption( | ||
{required this.groupName, required this.groupDesc}); | ||
String groupName; | ||
String groupDesc; | ||
List<BottomSwitcherOption> options = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 | ||
|
||
COCOAPODS: 1.14.1 | ||
COCOAPODS: 1.13.0 |