-
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
116 additions
and
72 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
45 changes: 45 additions & 0 deletions
45
notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_Checkbox.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,45 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:you_flutter/state.dart'; | ||
|
||
main() { | ||
runApp(const MaterialApp(home: Scaffold(body: Form_Checkbox()))); | ||
} | ||
|
||
// ignore: camel_case_types | ||
class Form_Checkbox extends StatefulWidget { | ||
const Form_Checkbox({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _State(); | ||
} | ||
} | ||
|
||
class _State extends State<Form_Checkbox> { | ||
final Value<bool?> checkbox1 = (null as bool?).signal(); | ||
final Value<bool> checkbox2 = false.signal(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Watch( | ||
builder: (context) { | ||
return Column( | ||
children: <Widget>[ | ||
Row( | ||
children: [ | ||
const Text('tristate: true'), | ||
Checkbox(tristate: true, checkColor: Colors.white, value: checkbox1.value, onChanged: (value) => checkbox1.value = value), | ||
], | ||
), | ||
Row( | ||
children: [ | ||
const Text('tristate: false'), | ||
Checkbox(tristate: false, checkColor: Colors.white, value: checkbox2.value, onChanged: (value) => checkbox2.value = value!), | ||
], | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
notes/flutter_web/lib/routes/notes/cheatsheets/widgets/_examples/Form_SegmentButton.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,61 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:you_flutter/state.dart'; | ||
|
||
main() { | ||
runApp(const MaterialApp(home: Scaffold(body: Form_SegmentButton()))); | ||
} | ||
|
||
// ignore: camel_case_types | ||
class Form_SegmentButton extends StatefulWidget { | ||
const Form_SegmentButton({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _State(); | ||
} | ||
} | ||
|
||
class _State extends State<Form_SegmentButton> { | ||
final Value<ThemeMode> themeMode = ThemeMode.system.signal(); | ||
final Set<TargetPlatform> targetPlatforms = <TargetPlatform>{TargetPlatform.macOS, TargetPlatform.linux}.signal(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Watch(builder: (context) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
SegmentedButton<ThemeMode>( | ||
multiSelectionEnabled: false, | ||
segments: const <ButtonSegment<ThemeMode>>[ | ||
ButtonSegment<ThemeMode>(value: ThemeMode.light, label: Text('Light'), icon: Icon(Icons.sunny)), | ||
ButtonSegment<ThemeMode>(value: ThemeMode.system, label: Text('System'), icon: Icon(Icons.brightness_auto)), | ||
ButtonSegment<ThemeMode>(value: ThemeMode.dark, label: Text('Dark'), icon: Icon(Icons.dark_mode)), | ||
], | ||
selected: <ThemeMode>{themeMode.value}, | ||
onSelectionChanged: (newSelection) { | ||
themeMode.value = newSelection.first; | ||
}, | ||
), | ||
const SizedBox(height: 10), | ||
SegmentedButton<TargetPlatform>( | ||
segments: const <ButtonSegment<TargetPlatform>>[ | ||
ButtonSegment<TargetPlatform>(value: TargetPlatform.android, label: Text('android')), | ||
ButtonSegment<TargetPlatform>(value: TargetPlatform.fuchsia, label: Text('fuchsia')), | ||
ButtonSegment<TargetPlatform>(value: TargetPlatform.iOS, label: Text('iOS')), | ||
ButtonSegment<TargetPlatform>(value: TargetPlatform.linux, label: Text('linux')), | ||
ButtonSegment<TargetPlatform>(value: TargetPlatform.macOS, label: Text('macOS')), | ||
ButtonSegment<TargetPlatform>(value: TargetPlatform.windows, label: Text('windows')), | ||
], | ||
selected: targetPlatforms, | ||
onSelectionChanged: (newSelection) { | ||
targetPlatforms.clear(); | ||
targetPlatforms.addAll(newSelection); | ||
}, | ||
multiSelectionEnabled: true, | ||
), | ||
], | ||
); | ||
}); | ||
} | ||
} |
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