forked from firka/flutter
Add Material 3 RadioListTile example and update existing examples (#119716)
* Add Material 3 `RadioListTile` example and update existing examples * Update examples with `useMaterial3: true` and update example descriptions. * add a `ColorScheme` colour
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/radio_list_tile/custom_labeled_radio.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('LinkedLabelRadio contains RichText and Radio', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.LabeledRadioApp(),
|
||||
);
|
||||
|
||||
// Label text is in a RichText widget with the correct text.
|
||||
final RichText richText = tester.widget(find.byType(RichText).first);
|
||||
expect(richText.text.toPlainText(), 'First tappable label text');
|
||||
|
||||
// First Radio is initially unchecked.
|
||||
Radio<bool> radio = tester.widget(find.byType(Radio<bool>).first);
|
||||
expect(radio.value, true);
|
||||
expect(radio.groupValue, false);
|
||||
|
||||
// Last Radio is initially checked.
|
||||
radio = tester.widget(find.byType(Radio<bool>).last);
|
||||
expect(radio.value, false);
|
||||
expect(radio.groupValue, false);
|
||||
|
||||
// Tap the first radio.
|
||||
await tester.tap(find.byType(Radio<bool>).first);
|
||||
await tester.pump();
|
||||
|
||||
// First Radio is now checked.
|
||||
radio = tester.widget(find.byType(Radio<bool>).first);
|
||||
expect(radio.value, true);
|
||||
expect(radio.groupValue, true);
|
||||
|
||||
// Last Radio is now unchecked.
|
||||
radio = tester.widget(find.byType(Radio<bool>).last);
|
||||
expect(radio.value, false);
|
||||
expect(radio.groupValue, true);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/radio_list_tile/custom_labeled_radio.1.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Tapping LabeledRadio toggles the radio', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.LabeledRadioApp(),
|
||||
);
|
||||
|
||||
// First Radio is initially unchecked.
|
||||
Radio<bool> radio = tester.widget(find.byType(Radio<bool>).first);
|
||||
expect(radio.value, true);
|
||||
expect(radio.groupValue, false);
|
||||
|
||||
// Last Radio is initially checked.
|
||||
radio = tester.widget(find.byType(Radio<bool>).last);
|
||||
expect(radio.value, false);
|
||||
expect(radio.groupValue, false);
|
||||
|
||||
// Tap the first labeled radio to toggle the Radio widget.
|
||||
await tester.tap(find.byType(example.LabeledRadio).first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// First Radio is now checked.
|
||||
radio = tester.widget(find.byType(Radio<bool>).first);
|
||||
expect(radio.value, true);
|
||||
expect(radio.groupValue, true);
|
||||
|
||||
// Last Radio is now unchecked.
|
||||
radio = tester.widget(find.byType(Radio<bool>).last);
|
||||
expect(radio.value, false);
|
||||
expect(radio.groupValue, true);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/radio_list_tile/radio_list_tile.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Can update RadioListTile group value', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.RadioListTileApp(),
|
||||
);
|
||||
|
||||
// Find the number of RadioListTiles.
|
||||
expect(find.byType(RadioListTile<example.SingingCharacter>), findsNWidgets(2));
|
||||
|
||||
// The initial group value is lafayette for the first RadioListTile.
|
||||
RadioListTile<example.SingingCharacter> radioListTile = tester.widget(find.byType(RadioListTile<example.SingingCharacter>).first);
|
||||
expect(radioListTile.groupValue, example.SingingCharacter.lafayette);
|
||||
|
||||
// The initial group value is lafayette for the last RadioListTile.
|
||||
radioListTile = tester.widget(find.byType(RadioListTile<example.SingingCharacter>).last);
|
||||
expect(radioListTile.groupValue, example.SingingCharacter.lafayette);
|
||||
|
||||
// Tap the last RadioListTile to change the group value to jefferson.
|
||||
await tester.tap(find.byType(RadioListTile<example.SingingCharacter>).last);
|
||||
await tester.pump();
|
||||
|
||||
// The group value is now jefferson for the first RadioListTile.
|
||||
radioListTile = tester.widget(find.byType(RadioListTile<example.SingingCharacter>).first);
|
||||
expect(radioListTile.groupValue, example.SingingCharacter.jefferson);
|
||||
|
||||
// The group value is now jefferson for the last RadioListTile.
|
||||
radioListTile = tester.widget(find.byType(RadioListTile<example.SingingCharacter>).last);
|
||||
expect(radioListTile.groupValue, example.SingingCharacter.jefferson);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/radio_list_tile/radio_list_tile.1.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Radio aligns appropriately', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.RadioListTileApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(RadioListTile<example.Groceries>), findsNWidgets(3));
|
||||
|
||||
Offset tileTopLeft = tester.getTopLeft(find.byType(RadioListTile<example.Groceries>).at(0));
|
||||
Offset radioTopLeft = tester.getTopLeft(find.byType(Radio<example.Groceries>).at(0));
|
||||
|
||||
// The radio is centered vertically with the text.
|
||||
expect(radioTopLeft - tileTopLeft, const Offset(16.0, 16.0));
|
||||
|
||||
tileTopLeft = tester.getTopLeft(find.byType(RadioListTile<example.Groceries>).at(1));
|
||||
radioTopLeft = tester.getTopLeft(find.byType(Radio<example.Groceries>).at(1));
|
||||
|
||||
// The radio is centered vertically with the text.
|
||||
expect(radioTopLeft - tileTopLeft, const Offset(16.0, 30.0));
|
||||
|
||||
tileTopLeft = tester.getTopLeft(find.byType(RadioListTile<example.Groceries>).at(2));
|
||||
radioTopLeft = tester.getTopLeft(find.byType(Radio<example.Groceries>).at(2));
|
||||
|
||||
// The radio is aligned to the top vertically with the text.
|
||||
expect(radioTopLeft - tileTopLeft, const Offset(16.0, 8.0));
|
||||
});
|
||||
|
||||
testWidgets('Radios can be checked', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.RadioListTileApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(RadioListTile<example.Groceries>), findsNWidgets(3));
|
||||
final Finder radioListTile = find.byType(RadioListTile<example.Groceries>);
|
||||
|
||||
// Initially the first radio is checked.
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(0)).groupValue,
|
||||
example.Groceries.pickles,
|
||||
);
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(1)).groupValue,
|
||||
example.Groceries.pickles,
|
||||
);
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(2)).groupValue,
|
||||
example.Groceries.pickles,
|
||||
);
|
||||
|
||||
// Tap the second radio.
|
||||
await tester.tap(find.byType(Radio<example.Groceries>).at(1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The second radio is checked.
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(0)).groupValue,
|
||||
example.Groceries.tomato,
|
||||
);
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(1)).groupValue,
|
||||
example.Groceries.tomato,
|
||||
);
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(2)).groupValue,
|
||||
example.Groceries.tomato,
|
||||
);
|
||||
|
||||
// Tap the third radio.
|
||||
await tester.tap(find.byType(Radio<example.Groceries>).at(2));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The third radio is checked.
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(0)).groupValue,
|
||||
example.Groceries.lettuce,
|
||||
);
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(1)).groupValue,
|
||||
example.Groceries.lettuce,
|
||||
);
|
||||
expect(
|
||||
tester.widget<RadioListTile<example.Groceries>>(radioListTile.at(2)).groupValue,
|
||||
example.Groceries.lettuce,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/radio_list_tile/radio_list_tile.toggleable.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('RadioListTile is toggleable', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.RadioListTileApp(),
|
||||
);
|
||||
|
||||
// Initially the third radio button is not selected.
|
||||
Radio<int> radio = tester.widget(find.byType(Radio<int>).at(2));
|
||||
expect(radio.value, 2);
|
||||
expect(radio.groupValue, null);
|
||||
|
||||
// Tap the third radio button.
|
||||
await tester.tap(find.text('Philip Schuyler'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The third radio button is now selected.
|
||||
radio = tester.widget(find.byType(Radio<int>).at(2));
|
||||
expect(radio.value, 2);
|
||||
expect(radio.groupValue, 2);
|
||||
|
||||
// Tap the third radio button again.
|
||||
await tester.tap(find.text('Philip Schuyler'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The third radio button is now unselected.
|
||||
radio = tester.widget(find.byType(Radio<int>).at(2));
|
||||
expect(radio.value, 2);
|
||||
expect(radio.groupValue, null);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user