From 29aabab5e7599de698114fa1b70804f30a4c65e7 Mon Sep 17 00:00:00 2001 From: Chen Peng Date: Thu, 13 Jun 2024 22:55:19 +0800 Subject: [PATCH] [flutter_web] ChoiceChip --- notes/flutter_web/lib/assets.g.dart | 4 ++ .../widgets/_examples/Form_ActionChip.dart | 28 +++++++++++++ .../widgets/_examples/Form_ChoiceChip.dart | 36 ++++++++++++++++ .../notes/cheatsheets/widgets/page.dart | 42 ++----------------- 4 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ActionChip.dart create mode 100644 notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ChoiceChip.dart diff --git a/notes/flutter_web/lib/assets.g.dart b/notes/flutter_web/lib/assets.g.dart index d379ff0e..e7d87789 100644 --- a/notes/flutter_web/lib/assets.g.dart +++ b/notes/flutter_web/lib/assets.g.dart @@ -99,23 +99,27 @@ mixin AssetsMixin { final Asset lib_routes_notes_Improve_app_event_listener_lifeycle_page_dart = Asset('lib/routes/notes/Improve_app/event&listener&lifeycle/page.dart'); final Asset lib_routes_notes_Improve_app_i18n_page_dart = Asset('lib/routes/notes/Improve_app/i18n/page.dart'); final Asset lib_routes_notes_pure_dart_exception_page_dart = Asset('lib/routes/notes/pure_dart/exception/page.dart'); + final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_ActionChip_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_ActionChip.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_ButtonStyleButton_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_ButtonStyleButton.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_BottomAppBar_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_BottomAppBar.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_Menu_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_Menu.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_TabBar_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_TabBar.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_NavigationDrawer_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_NavigationDrawer.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Spacer_Placeholder_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Spacer_Placeholder.dart'); + final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_ChoiceChip_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_ChoiceChip.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_Checkbox_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_Checkbox.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_SliverAppBar_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_SliverAppBar.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_LayoutCore_ContainerCell_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/LayoutCore_ContainerCell.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_AppBar_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_AppBar.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_SearchAnchor_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_SearchAnchor.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_FloatingActionButton_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_FloatingActionButton.dart'); + final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_CheckboxListTile_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_CheckboxListTile.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_NavigationBar_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_NavigationBar.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Spacer_Spacer_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Spacer_Spacer.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Navigation_NavigationRail_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Navigation_NavigationRail.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_SegmentButton_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_SegmentButton.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_IconButton_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_IconButton.dart'); + final Asset lib_routes_notes_cheatsheets_widgets__examples_Form_Chip_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Form_Chip.dart'); final Asset lib_routes_notes_cheatsheets_widgets__examples_Spacer_Divider_dart = Asset('lib/routes/notes/cheatsheets/widgets/_examples/Spacer_Divider.dart'); } diff --git a/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ActionChip.dart b/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ActionChip.dart new file mode 100644 index 00000000..02c68fac --- /dev/null +++ b/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ActionChip.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import 'package:you_flutter/state.dart'; + +main() { + runApp(MaterialApp(home: Scaffold(body: Form_ActionChip()))); +} + +// ignore: camel_case_types +class Form_ActionChip extends StatelessWidget { + Form_ActionChip({super.key}); + + final Value favorite = false.signal(); + + @override + Widget build(BuildContext context) { + return Watch(builder: (context) { + return Column(children: [ + Wrap(children: [ + ActionChip( + avatar: Icon(favorite.value ? Icons.favorite : Icons.favorite_border), + label: const Text("favorite"), + onPressed: () => favorite.value = !favorite.value, + ), + ]), + ]); + }); + } +} diff --git a/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ChoiceChip.dart b/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ChoiceChip.dart new file mode 100644 index 00000000..2f511979 --- /dev/null +++ b/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_ChoiceChip.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; +import 'package:you_flutter/state.dart'; + +main() { + runApp(MaterialApp(home: Scaffold(body: Form_ChoiceChip()))); +} + +// ignore: camel_case_types +class Form_ChoiceChip extends StatelessWidget { + Form_ChoiceChip({super.key}); + + final Value selected = (null as TargetPlatform?).signal(); + + @override + Widget build(BuildContext context) { + return Watch( + builder: (context) { + return Column( + children: [ + Wrap( + children: [ + for (var t in TargetPlatform.values) + ChoiceChip( + label: Text(t.name), + selected: selected.value == t, + onSelected: (bool value) { + selected.value = value ? t : null; + }), + ], + ), + ], + ); + }, + ); + } +} diff --git a/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/page.dart b/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/page.dart index a73635af..88e6fadb 100644 --- a/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/page.dart +++ b/notes/flutter_web/lib/routes/notes/cheatsheets/widgets/page.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_web/app.dart'; +import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_ActionChip.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_ButtonStyleButton.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_Checkbox.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_CheckboxListTile.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_Chip.dart'; +import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_ChoiceChip.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_FloatingActionButton.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_IconButton.dart'; import 'package:flutter_web/routes/notes/cheatsheets/widgets/_examples/Form_SearchAnchor.dart'; @@ -61,8 +63,8 @@ void build(BuildContext context, Cell print) { FlutterExample(title: "Checkbox", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_Checkbox_dart, child: const Form_Checkbox()), FlutterExample(title: "CheckboxListTile", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_CheckboxListTile_dart, child: Form_CheckboxListTile()), FlutterExample(title: "Chip", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_Chip_dart, child: Form_Chip()), - FlutterExample(title: "ActionChip", child: buttonAndInput.actionChip()), - FlutterExample(title: "ChoiceChip", child: buttonAndInput.choiceChip()), + FlutterExample(title: "ActionChip", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_ActionChip_dart, child: Form_ActionChip()), + FlutterExample(title: "ChoiceChip", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_ChoiceChip_dart, child: Form_ChoiceChip()), FlutterExample(title: "FilterChip", child: buttonAndInput.filterChip()), FlutterExample(title: "InputChip", child: buttonAndInput.inputChip()), FlutterExample(title: "datePicker", child: buttonAndInput.datePicker()), @@ -95,20 +97,6 @@ void build(BuildContext context, Cell print) { } class ButtonAndInput { - Widget actionChip() { - final Value favorite = false.signal(); - return Watch(builder: (context) { - return Column(children: [ - Wrap(children: [ - ActionChip( - avatar: Icon(favorite.value ? Icons.favorite : Icons.favorite_border), - label: const Text("favorite"), - onPressed: () => favorite.value = !favorite.value, - ), - ]), - ]); - }); - } Widget filterChip() { final Set selected = {}.signal(); @@ -139,28 +127,6 @@ class ButtonAndInput { ); } - Widget choiceChip() { - final Value selected = (null as TargetPlatform?).signal(); - return Watch( - builder: (context) { - return Column( - children: [ - Wrap( - children: [ - for (var t in TargetPlatform.values) - ChoiceChip( - label: Text(t.name), - selected: selected.value == t, - onSelected: (bool value) { - selected.value = value ? t : null; - }), - ], - ), - ], - ); - }, - ); - } Widget inputChip() { final TextEditingController controller = TextEditingController();