Skip to content

Commit

Permalink
[flutter_web] Chip
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Jun 13, 2024
1 parent ab99429 commit 8356b2e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 43 deletions.
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_CheckboxListTile())));
}

// ignore: camel_case_types
class Form_CheckboxListTile extends StatelessWidget {
Form_CheckboxListTile({super.key});

final Value<bool?> checkboxListTile1 = (null as bool?).signal();
final Value<bool> checkboxListTile2 = false.signal();

@override
Widget build(BuildContext context) {
return Watch(
builder: (context) {
return Column(
children: <Widget>[
CheckboxListTile(tristate: true, value: checkboxListTile1.value, title: const Text('tristate: true'), onChanged: (value) => checkboxListTile1.value = value),
CheckboxListTile(tristate: false, value: checkboxListTile2.value, title: const Text('tristate: false'), onChanged: (value) => checkboxListTile2.value = value!),
],
);
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:you_flutter/state.dart';

main() {
runApp(MaterialApp(home: Scaffold(body: Form_Chip())));
}

// ignore: camel_case_types
class Form_Chip extends StatelessWidget {
Form_Chip({super.key});

final Set<TargetPlatform> targets = Set.of(TargetPlatform.values).signal();

@override
Widget build(BuildContext context) {
return Watch(builder: (context) {
return Column(children: <Widget>[
Wrap(
children: [
for (var target in targets)
Chip(
avatar: CircleAvatar(child: Text(target.name[0])),
label: Text(target.name),
onDeleted: () => targets.remove(target),
)
],
),
FilledButton(
onPressed: () {
targets.clear();
targets.addAll(TargetPlatform.values);
},
child: const Text("Reset")),
]);
});
}
}
47 changes: 4 additions & 43 deletions notes/flutter_web/lib/routes/notes/cheatsheets/widgets/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter/services.dart';
import 'package:flutter_web/app.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_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 @@ -57,8 +59,8 @@ void build(BuildContext context, Cell print) {
FlutterExample(title: "SearchAnchor", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_SearchAnchor_dart, child: const Form_SearchAnchor()),
FlutterExample(title: "SegmentButton", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_SegmentButton_dart, child: const Form_SegmentButton()),
FlutterExample(title: "Checkbox", source: assets.lib_routes_notes_cheatsheets_widgets__examples_Form_Checkbox_dart, child: const Form_Checkbox()),
FlutterExample(title: "CheckboxListTile", child: buttonAndInput.checkboxListTile()),
FlutterExample(title: "Chip", child: buttonAndInput.chip()),
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: "FilterChip", child: buttonAndInput.filterChip()),
Expand Down Expand Up @@ -93,47 +95,6 @@ void build(BuildContext context, Cell print) {
}

class ButtonAndInput {

Widget checkboxListTile() {
final Value<bool?> checkboxListTile1 = (null as bool?).signal();
final Value<bool> checkboxListTile2 = false.signal();
return Watch(
builder: (context) {
return Column(
children: <Widget>[
CheckboxListTile(tristate: true, value: checkboxListTile1.value, title: const Text('tristate: true'), onChanged: (value) => checkboxListTile1.value = value),
CheckboxListTile(tristate: false, value: checkboxListTile2.value, title: const Text('tristate: false'), onChanged: (value) => checkboxListTile2.value = value!),
],
);
},
);
}

Widget chip() {
final Set<TargetPlatform> targets = Set.of(TargetPlatform.values).signal();

return Watch(builder: (context) {
return Column(children: <Widget>[
Wrap(
children: [
for (var target in targets)
Chip(
avatar: CircleAvatar(child: Text(target.name[0])),
label: Text(target.name),
onDeleted: () => targets.remove(target),
)
],
),
FilledButton(
onPressed: () {
targets.clear();
targets.addAll(TargetPlatform.values);
},
child: const Text("Reset")),
]);
});
}

Widget actionChip() {
final Value<bool> favorite = false.signal();
return Watch(builder: (context) {
Expand Down

0 comments on commit 8356b2e

Please sign in to comment.