flutter-test

Flutter: Test that a specific exception is thrown

百般思念 提交于 2019-12-01 14:48:51
问题 in short, throwsA(anything) does not suffice for me while unit testing in dart. How to I test for a specific error message or type ? Here is the error I would like to catch: class MyCustErr implements Exception { String term; String errMsg() => 'You have already added a container with the id $term. Duplicates are not allowed'; MyCustErr({this.term}); } here is the current assertion that passes, but would like to check for the error type above: expect(() => operations.lookupOrderDetails(),

How to test navigation via Navigator in Flutter

别说谁变了你拦得住时间么 提交于 2019-12-01 05:14:20
Let's say, I have a test for a screen in Flutter using WidgetTester . There is a button, which executes a navigation via Navigator . I would like to test behavior of that button. Widget/Screen class MyScreen extends StatefulWidget { MyScreen({Key key}) : super(key: key); @override _MyScreenState createState() => _MyScreenScreenState(); } class _MyScreenState extends State<MyScreen> { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: RaisedButton( onPressed: () { Navigator.of(context).pushNamed("/nextscreen"); }, child: Text(Strings.traktTvUrl) ) ) ); } } Test

How to test navigation via Navigator in Flutter

房东的猫 提交于 2019-12-01 02:25:35
问题 Let's say, I have a test for a screen in Flutter using WidgetTester . There is a button, which executes a navigation via Navigator . I would like to test behavior of that button. Widget/Screen class MyScreen extends StatefulWidget { MyScreen({Key key}) : super(key: key); @override _MyScreenState createState() => _MyScreenScreenState(); } class _MyScreenState extends State<MyScreen> { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: RaisedButton( onPressed:

Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'

你离开我真会死。 提交于 2019-12-01 02:07:17
I have just started using Flutter and i'm having this problem while running my code "Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'". And the interesting part is that i dont even have this 'StatelessWidget' in my code. import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override State<StatefulWidget> createState() { // TODO: implement createState return _MyAppState(); } } class _MyAppState extends State<MyApp> { List<String> _bars = ['Olivio bar']; @override Widget build(BuildContext context) {

Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'

你说的曾经没有我的故事 提交于 2019-11-30 16:23:23
问题 I have just started using Flutter and i'm having this problem while running my code "Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'". And the interesting part is that i dont even have this 'StatelessWidget' in my code. import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override State<StatefulWidget> createState() { // TODO: implement createState return _MyAppState(); } } class _MyAppState

How to test Flutter widgets on different screen sizes?

江枫思渺然 提交于 2019-11-27 23:14:17
I have a Flutter widget which shows extra data depending on the screen size. Does anyone know a way of testing this widget on multiple different screen sizes? I've had a look through the widget_tester source code but can't find anything. You can specify custom surface size by using TestWidgetsFlutterBinding The following code will run a test with a screen size of 42x42 import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); testWidgets("foo", (tester) async {