forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Material 3
CheckboxListTile
example and update existing example…
…s (#118792) * Add Material 3 `CheckboxListTile` example and update existing examples * fix `list_tile.dart` doc issues * Remove unnecessary comma
- Loading branch information
1 parent
eced23e
commit 29ab437
Showing
12 changed files
with
424 additions
and
177 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
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
99 changes: 99 additions & 0 deletions
99
examples/api/lib/material/checkbox_list_tile/custom_labeled_checkbox.0.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,99 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Flutter code sample for custom labeled checkbox. | ||
|
||
import 'package:flutter/gestures.dart'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
void main() => runApp(const LabeledCheckBoxApp()); | ||
|
||
class LabeledCheckBoxApp extends StatelessWidget { | ||
const LabeledCheckBoxApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const MaterialApp( | ||
home: LabeledCheckBoxExample(), | ||
); | ||
} | ||
} | ||
|
||
class LinkedLabelCheckbox extends StatelessWidget { | ||
const LinkedLabelCheckbox({ | ||
super.key, | ||
required this.label, | ||
required this.padding, | ||
required this.value, | ||
required this.onChanged, | ||
}); | ||
|
||
final String label; | ||
final EdgeInsets padding; | ||
final bool value; | ||
final ValueChanged<bool> onChanged; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: padding, | ||
child: Row( | ||
children: <Widget>[ | ||
Expanded( | ||
child: RichText( | ||
text: TextSpan( | ||
text: label, | ||
style: const TextStyle( | ||
color: Colors.blueAccent, | ||
decoration: TextDecoration.underline, | ||
), | ||
recognizer: TapGestureRecognizer() | ||
..onTap = () { | ||
debugPrint('Label has been tapped.'); | ||
}, | ||
), | ||
), | ||
), | ||
Checkbox( | ||
value: value, | ||
onChanged: (bool? newValue) { | ||
onChanged(newValue!); | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class LabeledCheckBoxExample extends StatefulWidget { | ||
const LabeledCheckBoxExample({super.key}); | ||
|
||
@override | ||
State<LabeledCheckBoxExample> createState() => _LabeledCheckBoxExampleState(); | ||
} | ||
|
||
class _LabeledCheckBoxExampleState extends State<LabeledCheckBoxExample> { | ||
bool _isSelected = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Custom Labeled Checkbox Sample')), | ||
body: Center( | ||
child: LinkedLabelCheckbox( | ||
label: 'Linked, tappable label text', | ||
padding: const EdgeInsets.symmetric(horizontal: 20.0), | ||
value: _isSelected, | ||
onChanged: (bool newValue) { | ||
setState(() { | ||
_isSelected = newValue; | ||
}); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
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
Oops, something went wrong.