-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
75 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
42 changes: 42 additions & 0 deletions
42
notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_FilterChip.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,42 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:you_flutter/state.dart'; | ||
|
||
main() { | ||
runApp(MaterialApp(home: Scaffold(body: Form_FilterChip()))); | ||
} | ||
|
||
// ignore: camel_case_types | ||
class Form_FilterChip extends StatelessWidget { | ||
Form_FilterChip({super.key}); | ||
|
||
final Set<String> selected = <String>{}.signal(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Watch( | ||
builder: (context) { | ||
return Column( | ||
children: <Widget>[ | ||
Wrap( | ||
children: [ | ||
for (var t in TargetPlatform.values) | ||
FilterChip( | ||
label: Text(t.name), | ||
selected: selected.contains(t.name), | ||
onSelected: (bool value) { | ||
if (value) { | ||
selected.add(t.name); | ||
} else { | ||
selected.remove(t.name); | ||
} | ||
}, | ||
) | ||
], | ||
), | ||
FilledButton(onPressed: () => selected.clear(), child: const Text("Reset")), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_InputChip.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,67 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:you_flutter/state.dart'; | ||
|
||
main() { | ||
runApp(MaterialApp(home: Scaffold(body: Form_InputChip()))); | ||
} | ||
|
||
// ignore: camel_case_types | ||
class Form_InputChip extends StatefulWidget { | ||
Form_InputChip({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _State(); | ||
} | ||
} | ||
|
||
class _State extends State<Form_InputChip> { | ||
final TextEditingController controller = TextEditingController(); | ||
final List<String> tags = <String>[].signal(); | ||
|
||
@override | ||
void dispose() { | ||
controller.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Watch( | ||
watchListenable: controller, | ||
builder: (context) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
TextField( | ||
controller: controller, | ||
decoration: const InputDecoration( | ||
prefixIcon: Icon(Icons.add), | ||
hintText: 'Write a tag, enter to add', | ||
), | ||
onSubmitted: (_) { | ||
if (controller.text.isNotEmpty) { | ||
if (!tags.contains(controller.text)) { | ||
tags.add(controller.text); | ||
} | ||
controller.clear(); // 清空TextField | ||
} | ||
}, | ||
), | ||
Wrap( | ||
spacing: 8.0, | ||
children: tags.map((tag) { | ||
return InputChip( | ||
avatar: const Icon(Icons.tag), | ||
label: Text(tag), | ||
onDeleted: () => tags.remove(tag), | ||
deleteIcon: const Icon(Icons.cancel), | ||
); | ||
}).toList(), | ||
) | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
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