Flutter: Testing for exceptions in widget tests

To catch exceptions thrown in a flutter test, use WidgetTester.takeException. This returns the last exception caught by the framework. await tester.tap(find.byIcon(Icons.send)); expect(tester.takeException(), isInstanceOf<UnrecognizedTermException>()); You also don’t need a throwsA matcher, since it is not being thrown from the method.

Flutter API Fetch and Sending Data from One screen to another screen

You should try to declare constructor the first page accept the id and push this id to second page or screen like this below code is first page Navigator.push( context, MaterialPageRoute( builder: (context) => ABC.withId( id, ), ), ) the create constructor inside second page screen class ABC extends StatefulWidget { @override _ABCState createState() => … Read more

How to test Flutter widgets on different screen sizes?

You can specify custom surface size by using WidgetTester The following code will run a test with a screen size of 42×42 import ‘package:flutter/widgets.dart’; import ‘package:flutter_test/flutter_test.dart’; void main() { testWidgets(“foo”, (tester) async { tester.binding.window.physicalSizeTestValue = Size(42, 42); // resets the screen to its original size after the test end addTearDown(tester.binding.window.clearPhysicalSizeTestValue); // TODO: do something }); … Read more