1
0
mirror of https://github.com/flutter/samples.git synced 2026-04-04 18:51:05 +00:00

Flutter 3.29 beta (#2571)

This commit is contained in:
Eric Windmill
2025-02-12 18:08:01 -05:00
committed by GitHub
parent d62c784789
commit 719fd72c38
685 changed files with 76244 additions and 53721 deletions

View File

@@ -14,17 +14,15 @@ void main() {
testWidgets('Enter pet details', (tester) async {
tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler(
const BasicMessageChannel<dynamic>(
'jsonMessageCodecDemo', JSONMessageCodec()),
'jsonMessageCodecDemo',
JSONMessageCodec(),
),
(dynamic message) async {
petList.add(message as Map);
},
);
var router = app.router('/petListScreen/addPetDetails');
await tester.pumpWidget(
MaterialApp.router(
routerConfig: router,
),
);
await tester.pumpWidget(MaterialApp.router(routerConfig: router));
// Enter the breed of cat.
await tester.enterText(find.byType(TextField), 'Persian');

View File

@@ -21,11 +21,7 @@ void main() {
// after decoding the message with codec used by the EventChannel.
void emitValues(ByteData? event) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage(
'eventChannelDemo',
event,
(reply) {},
);
.handlePlatformMessage('eventChannelDemo', event, (reply) {});
}
// Register a mock for EventChannel. EventChannel under the hood uses
@@ -33,27 +29,26 @@ void main() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMessageHandler('eventChannelDemo', (message) async {
// Decode the message into MethodCallHandler.
final methodCall = standardMethod.decodeMethodCall(message);
// Decode the message into MethodCallHandler.
final methodCall = standardMethod.decodeMethodCall(message);
if (methodCall.method == 'listen') {
// Emit new sensor values.
emitValues(standardMethod.encodeSuccessEnvelope(sensorValues));
emitValues(null);
return standardMethod.encodeSuccessEnvelope(null);
} else if (methodCall.method == 'cancel') {
return standardMethod.encodeSuccessEnvelope(null);
} else {
fail('Expected listen or cancel');
}
});
if (methodCall.method == 'listen') {
// Emit new sensor values.
emitValues(standardMethod.encodeSuccessEnvelope(sensorValues));
emitValues(null);
return standardMethod.encodeSuccessEnvelope(null);
} else if (methodCall.method == 'cancel') {
return standardMethod.encodeSuccessEnvelope(null);
} else {
fail('Expected listen or cancel');
}
});
});
testWidgets('EventChannel AccelerometerReadings Stream test',
(tester) async {
await tester.pumpWidget(const MaterialApp(
home: EventChannelDemo(),
));
testWidgets('EventChannel AccelerometerReadings Stream test', (
tester,
) async {
await tester.pumpWidget(const MaterialApp(home: EventChannelDemo()));
await tester.pumpAndSettle();

View File

@@ -23,9 +23,7 @@ void main() {
return MissingPluginException();
},
);
await tester.pumpWidget(const MaterialApp(
home: MethodChannelDemo(),
));
await tester.pumpWidget(const MaterialApp(home: MethodChannelDemo()));
// Initially the value of count should be 0.
expect(find.text('Value of count is 0'), findsOneWidget);

View File

@@ -12,14 +12,13 @@ import 'package:platform_channels/src/pet_list_screen.dart';
void main() {
group('PetListScreen tests', () {
const basicMessageChannel =
BasicMessageChannel<String?>('stringCodecDemo', StringCodec());
const basicMessageChannel = BasicMessageChannel<String?>(
'stringCodecDemo',
StringCodec(),
);
var petList = [
{
'petType': 'Dog',
'breed': 'Pug',
}
{'petType': 'Dog', 'breed': 'Pug'},
];
PetListModel? petListModel;
@@ -28,29 +27,37 @@ void main() {
// Mock for the pet list received from the platform.
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockDecodedMessageHandler(basicMessageChannel, (message) async {
petListModel = PetListModel.fromJson(message!);
return null;
});
petListModel = PetListModel.fromJson(message!);
return null;
});
// Mock for the index received from the Dart to delete the pet details,
// and send the updated pet list back to Dart.
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockDecodedMessageHandler(
const BasicMessageChannel<ByteData?>(
'binaryCodecDemo', BinaryCodec()), (message) async {
// Convert the ByteData to String.
final index = utf8.decoder.convert(message!.buffer
.asUint8List(message.offsetInBytes, message.lengthInBytes));
const BasicMessageChannel<ByteData?>(
'binaryCodecDemo',
BinaryCodec(),
),
(message) async {
// Convert the ByteData to String.
final index = utf8.decoder.convert(
message!.buffer.asUint8List(
message.offsetInBytes,
message.lengthInBytes,
),
);
// Remove the pet details at the given index.
petList.removeAt(int.parse(index));
// Remove the pet details at the given index.
petList.removeAt(int.parse(index));
// Send the updated petList back.
final map = {'petList': petList};
await basicMessageChannel.send(json.encode(map));
// Send the updated petList back.
final map = {'petList': petList};
await basicMessageChannel.send(json.encode(map));
return null;
});
return null;
},
);
});
test('convert json message to PetListModel', () {
@@ -70,11 +77,9 @@ void main() {
});
testWidgets('BuildPetList test', (tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: BuildPetList(petListModel!.petList),
),
));
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: BuildPetList(petListModel!.petList))),
);
expect(find.text('Pet type: Dog'), findsOneWidget);
expect(find.text('Pet breed: Pug'), findsOneWidget);

View File

@@ -12,15 +12,15 @@ void main() {
testWidgets('Platform Image test', (tester) async {
tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler(
const BasicMessageChannel<dynamic>(
'platformImageDemo', StandardMessageCodec()),
'platformImageDemo',
StandardMessageCodec(),
),
(dynamic message) async {
var byteData = await rootBundle.load('assets/eat_new_orleans.jpg');
return byteData.buffer.asUint8List();
},
);
await tester.pumpWidget(const MaterialApp(
home: PlatformImageDemo(),
));
await tester.pumpWidget(const MaterialApp(home: PlatformImageDemo()));
// Initially a PlaceHolder is displayed when imageData is null.
expect(find.byType(Placeholder), findsOneWidget);