File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [Checkbox.fillColor] .
8+
9+ class CheckboxExample extends StatelessWidget {
10+ const CheckboxExample ({super .key, required this .onChanged});
11+
12+ final ValueChanged <bool ?>? onChanged;
13+
14+ ValueChanged <bool ?>? get _nullableOnChanged => onChanged;
15+ bool get _value => true ;
16+
17+ @override
18+ Widget build (BuildContext context) {
19+ return
20+ // #region body
21+ Checkbox (
22+ value: _value,
23+ // If `onChanged` is null, this checkbox is disabled.
24+ // If `onChanged` is not null, this checkbox is enabled.
25+ onChanged: _nullableOnChanged,
26+ fillColor: WidgetStateProperty .resolveWith <Color >((
27+ Set <WidgetState > states,
28+ ) {
29+ if (states.contains (WidgetState .disabled)) {
30+ return Colors .orange.withValues (alpha: .32 );
31+ }
32+ return Colors .orange;
33+ }),
34+ )
35+ // #endregion body
36+ ;
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [CheckboxListTile] .
8+
9+ class CheckboxListTileExample extends StatelessWidget {
10+ const CheckboxListTileExample ({super .key});
11+
12+ @override
13+ Widget build (BuildContext context) {
14+ return
15+ // #region body
16+ ColoredBox (
17+ color: Colors .green,
18+ child: Material (
19+ child: CheckboxListTile (
20+ tileColor: Colors .red,
21+ title: const Text ('CheckboxListTile with red background' ),
22+ value: true ,
23+ onChanged: (bool ? value) {},
24+ ),
25+ ),
26+ )
27+ // #endregion body
28+ ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [CheckboxListTile.onChanged] .
8+
9+ class CheckboxListTileExample extends StatefulWidget {
10+ const CheckboxListTileExample ({super .key});
11+
12+ @override
13+ State <CheckboxListTileExample > createState () =>
14+ _CheckboxListTileExampleState ();
15+ }
16+
17+ class _CheckboxListTileExampleState extends State <CheckboxListTileExample > {
18+ bool ? _throwShotAway = false ;
19+
20+ @override
21+ Widget build (BuildContext context) {
22+ return
23+ // #region body
24+ CheckboxListTile (
25+ value: _throwShotAway,
26+ onChanged: (bool ? newValue) {
27+ setState (() {
28+ _throwShotAway = newValue;
29+ });
30+ },
31+ title: const Text ('Throw away your shot' ),
32+ )
33+ // #endregion body
34+ ;
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [Radio.fillColor] .
8+
9+ class RadioExample extends StatelessWidget {
10+ const RadioExample ({super .key});
11+
12+ @override
13+ Widget build (BuildContext context) {
14+ return
15+ // #region body
16+ Radio <int >(
17+ value: 1 ,
18+ fillColor: WidgetStateProperty .resolveWith <Color >((
19+ Set <WidgetState > states,
20+ ) {
21+ if (states.contains (WidgetState .disabled)) {
22+ return Colors .orange.withValues (alpha: .32 );
23+ }
24+ return Colors .orange;
25+ }),
26+ )
27+ // #endregion body
28+ ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [RadioListTile] .
8+
9+ enum Meridiem { am, pm }
10+
11+ class RadioListTileExample extends StatelessWidget {
12+ const RadioListTileExample ({super .key});
13+
14+ @override
15+ Widget build (BuildContext context) {
16+ return
17+ // #region body
18+ const ColoredBox (
19+ color: Colors .green,
20+ child: Material (
21+ child: RadioListTile <Meridiem >(
22+ tileColor: Colors .red,
23+ title: Text ('AM' ),
24+ value: Meridiem .am,
25+ ),
26+ ),
27+ )
28+ // #endregion body
29+ ;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/checkbox/checkbox.snippet.0.dart'
8+ as example;
9+
10+ void main () {
11+ testWidgets ('Checkbox fillColor resolves based on enabled state' , (
12+ WidgetTester tester,
13+ ) async {
14+ Widget buildApp ({required ValueChanged <bool ?>? onChanged}) {
15+ return MaterialApp (
16+ home: Scaffold (
17+ body: Center (child: example.CheckboxExample (onChanged: onChanged)),
18+ ),
19+ );
20+ }
21+
22+ await tester.pumpWidget (buildApp (onChanged: (bool ? _) {}));
23+ await tester.pumpAndSettle ();
24+ expect (find.byType (Checkbox ), paints..rrect (color: Colors .orange.shade500));
25+
26+ await tester.pumpWidget (buildApp (onChanged: null ));
27+ await tester.pumpAndSettle ();
28+ expect (
29+ find.byType (Checkbox ),
30+ paints..rrect (color: Colors .orange.withValues (alpha: .32 )),
31+ );
32+ });
33+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/checkbox_list_tile/checkbox_list_tile.snippet.0.dart'
8+ as example;
9+
10+ void main () {
11+ testWidgets ('CheckboxListTile renders with red tileColor inside Material' , (
12+ WidgetTester tester,
13+ ) async {
14+ await tester.pumpWidget (
15+ const MaterialApp (
16+ home: Scaffold (body: example.CheckboxListTileExample ()),
17+ ),
18+ );
19+
20+ expect (find.text ('CheckboxListTile with red background' ), findsOneWidget);
21+ expect (
22+ find.byType (example.CheckboxListTileExample ),
23+ paints
24+ ..rect (color: Colors .green.shade500)
25+ ..rect (color: Colors .red.shade500),
26+ );
27+ });
28+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/checkbox_list_tile/checkbox_list_tile.snippet.1.dart'
8+ as example;
9+
10+ void main () {
11+ testWidgets ('CheckboxListTile onChanged toggles checked state' , (
12+ WidgetTester tester,
13+ ) async {
14+ await tester.pumpWidget (
15+ const MaterialApp (
16+ home: Scaffold (body: example.CheckboxListTileExample ()),
17+ ),
18+ );
19+
20+ expect (
21+ tester.widget <CheckboxListTile >(find.byType (CheckboxListTile )).value,
22+ isFalse,
23+ );
24+
25+ await tester.tap (find.text ('Throw away your shot' ));
26+ await tester.pumpAndSettle ();
27+
28+ expect (
29+ tester.widget <CheckboxListTile >(find.byType (CheckboxListTile )).value,
30+ isTrue,
31+ );
32+ });
33+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/radio/radio.snippet.0.dart' as example;
8+
9+ void main () {
10+ testWidgets ('Radio fillColor resolves based on enabled state' , (
11+ WidgetTester tester,
12+ ) async {
13+ await tester.pumpWidget (
14+ MaterialApp (
15+ home: Scaffold (
16+ body: Center (
17+ child: RadioGroup <int >(
18+ groupValue: 1 ,
19+ onChanged: (int ? _) {},
20+ child: const example.RadioExample (),
21+ ),
22+ ),
23+ ),
24+ ),
25+ );
26+ await tester.pumpAndSettle ();
27+ expect (
28+ find.byType (Radio <int >),
29+ paints
30+ ..circle ()
31+ ..circle (color: Colors .orange.shade500),
32+ );
33+
34+ await tester.pumpWidget (
35+ const MaterialApp (
36+ home: Scaffold (body: Center (child: example.RadioExample ())),
37+ ),
38+ );
39+ await tester.pumpAndSettle ();
40+ expect (
41+ find.byType (Radio <int >),
42+ paints
43+ ..circle ()
44+ ..circle (color: Colors .orange.withValues (alpha: .32 )),
45+ );
46+ });
47+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/radio_list_tile/radio_list_tile.snippet.0.dart'
8+ as example;
9+
10+ void main () {
11+ testWidgets ('RadioListTile renders with red tileColor inside Material' , (
12+ WidgetTester tester,
13+ ) async {
14+ await tester.pumpWidget (
15+ const MaterialApp (home: Scaffold (body: example.RadioListTileExample ())),
16+ );
17+
18+ expect (find.text ('AM' ), findsOneWidget);
19+ expect (
20+ find.byType (example.RadioListTileExample ),
21+ paints
22+ ..rect (color: Colors .green.shade500)
23+ ..rect (color: Colors .red.shade500),
24+ );
25+ });
26+ }
You can’t perform that action at this time.
0 commit comments