Skip to content

Commit

Permalink
[flutter_web] ChoiceChip
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Jun 13, 2024
1 parent 8356b2e commit 29aabab
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 38 deletions.
4 changes: 4 additions & 0 deletions notes/flutter_web/lib/assets.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<bool> favorite = false.signal();

@override
Widget build(BuildContext context) {
return Watch(builder: (context) {
return Column(children: <Widget>[
Wrap(children: [
ActionChip(
avatar: Icon(favorite.value ? Icons.favorite : Icons.favorite_border),
label: const Text("favorite"),
onPressed: () => favorite.value = !favorite.value,
),
]),
]);
});
}
}
Original file line number Diff line number Diff line change
@@ -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<TargetPlatform?> selected = (null as TargetPlatform?).signal();

@override
Widget build(BuildContext context) {
return Watch(
builder: (context) {
return Column(
children: <Widget>[
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;
}),
],
),
],
);
},
);
}
}
42 changes: 4 additions & 38 deletions notes/flutter_web/lib/routes/notes/cheatsheets/widgets/page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -95,20 +97,6 @@ void build(BuildContext context, Cell print) {
}

class ButtonAndInput {
Widget actionChip() {
final Value<bool> favorite = false.signal();
return Watch(builder: (context) {
return Column(children: <Widget>[
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<String> selected = <String>{}.signal();
Expand Down Expand Up @@ -139,28 +127,6 @@ class ButtonAndInput {
);
}

Widget choiceChip() {
final Value<TargetPlatform?> selected = (null as TargetPlatform?).signal();
return Watch(
builder: (context) {
return Column(
children: <Widget>[
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();
Expand Down

0 comments on commit 29aabab

Please sign in to comment.