flutter-test

Is it possible to access children/parent widgets from a given widget, in a Flutter test?

核能气质少年 提交于 2020-01-14 07:03:26
问题 I'm writing unit and integration tests for Flutter. Is it possible to access children/parent widgets from a given widget? 回答1: Yes, you can use find.descendant and Element.ancestorWidgetOfExactType. Examples: // Finds a RichText widget that a descendant (child/grand-child/etc) of a // tab widget with text "Tab 1" find.descendant(of: find.text('Tab 1'), matching: find.byType(RichText)); // Finds a parent widget of type MyParentWidget. tester.element(find.byType(MyChildWidget))

How to crop circular(or Square or Hexagon ) area from canvas in Flutter

痞子三分冷 提交于 2020-01-06 04:49:08
问题 I want to crop a rectangular image-file and make it circular or square or hexagon shape and save it as image-file locally . I have a bitmap and I want to crop a circular or hexagon region from this bitmap. All pixels outside the circle should be transparent. How can I do this? I found the similar question in android platform. But unable to find a good resource that really help or direct me to achieve this in flutter. Please share me the idea to achieve this result. 回答1: Use Clipper to crop

Flutter error: Could not download bcprov-jdk15on.jar (org.bouncycastle:bcprov-jdk15on:1.56)

最后都变了- 提交于 2020-01-03 16:51:17
问题 I'm failing to run my first ever Flutter App. Getting the below error. Launching lib\main.dart on Android SDK built for x86 in debug mode... Initializing gradle... Resolving dependencies... * Error running Gradle: Exit code 1 from: D:\PROJECTS\softwareProjects\AndroidProjects\flutter_app_2\android\gradlew.bat app:properties: Download https://jcenter.bintray.com/org/bouncycastle/bcprov-jdk15on/1.56/bcprov-jdk15on-1.56.jar FAILURE: Build failed with an exception. * What went wrong: A problem

Flutter: Testing for exceptions in widget tests

前提是你 提交于 2020-01-02 04:47:11
问题 How do I go about making sure the ui (widget) throws an exception during widget testing in Flutter. Here is my code that does not work: expect( () => tester.tap(find.byIcon(Icons.send)), throwsA(const TypeMatcher<UnrecognizedTermException>()), ); It fails with the following error ... Expected: throws <Instance of 'TypeMatcher<UnrecognizedTermException>'> Actual: <Closure: () => Future<void>> Which: returned a Future that emitted <null> OR......should I be testing how the UI handles an

Flutter: Timer Issue During Testing

痞子三分冷 提交于 2020-01-01 16:02:10
问题 I have a periodic timer in one of my StatelessWidget 's. Without going too much into detail, here is a snippet of code producing a timer: class AnniversaryHomePage extends StatelessWidget { . . . void _updateDisplayTime(StoreInheritedWidget inheritedWidget) { String anniversaryString = inheritedWidget.prefs.getString('anniversaryDate'); inheritedWidget.store.dispatch(DateTime.parse(anniversaryString)); } /// Widget Methods @override Widget build(BuildContext context) { final inheritedWidget =

How to find off-screen ListView child in widget tests?

痴心易碎 提交于 2019-12-24 14:16:26
问题 When displaying multiple children in a ListView, if a child is off-screen it can't be found by a widget test. Here's a full example: main.dart import 'package:flutter/material.dart'; void main() => runApp(App()); class App extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp(home: Scaffold(body: Test())); } } class Test extends StatelessWidget { @override Widget build(BuildContext context) { return ListView( children: <Widget>[ Container( height: 600,

How to wait for a future to complete in Flutter widget test?

一个人想着一个人 提交于 2019-12-21 14:36:19
问题 I am trying to perform a widget test, specifically navigation test. I am using bloc architecture, setting a stream on the bloc triggers a series of events inside the bloc, gets session info from the server call (which returns a future of session info object), on successful server call a login stream is set and the widget has a stream subscription to this stream and navigates to the next screen. I am using mockito to mock the server call and stubbing the server call to return a future of

How to wait for a future to complete in Flutter widget test?

南笙酒味 提交于 2019-12-21 14:35:06
问题 I am trying to perform a widget test, specifically navigation test. I am using bloc architecture, setting a stream on the bloc triggers a series of events inside the bloc, gets session info from the server call (which returns a future of session info object), on successful server call a login stream is set and the widget has a stream subscription to this stream and navigates to the next screen. I am using mockito to mock the server call and stubbing the server call to return a future of

How to test Flutter widgets on different screen sizes?

試著忘記壹切 提交于 2019-12-17 09:48:51
问题 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. 回答1: 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

How to widget-test FutureBuilder with unresolved Future

旧时模样 提交于 2019-12-12 23:01:01
问题 I wonder how I can test the case when a future is not yet completed in flutter widget tests. The widget should show a spinner as long as the future is unresolved. I tride this test case: testWidgets( 'should show a spinner when loading', (WidgetTester tester) async { when(valueRepository.getValues()) .thenAnswer((_) => Future.delayed(Duration(seconds: 30), () => [])); await tester.pumpWidget(withApp(ValueListPage( valueRepository: valueRepository, ))); await tester.pumpAndSettle( Duration