cmdrootaccess / another-flushbar

A flexible widget for user notification. Customize your text, button, duration, animations and much more. For Android devs, it is made to replace Snackbars and Toasts.
https://pub.dev/packages/another_flushbar
MIT License
145 stars 89 forks source link

Flushbar Not Testable With duration #61

Open f-hoedl opened 2 years ago

f-hoedl commented 2 years ago

Minimal reproducable example:

Widget with flushbar:

import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/material.dart';

class FlushbarExample extends StatelessWidget {
  const FlushbarExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      child: Text("Button"),
      onPressed: () {
        Flushbar(
          flushbarPosition: FlushbarPosition.BOTTOM,
          message: "Help",
          duration: const Duration(seconds: 3),
        ).show(context);
      },
    );
  }
}

Testclass:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'flush_example.dart';

main() {
  testWidgets(
    "test flushbar",
    (WidgetTester tester) async {
      await tester.pumpWidget(
        const MaterialApp(
          home: Scaffold(
            body: FlushbarExample(),
          ),
        ),
      );
      var button = find.text("Button");
      expect(button, findsOneWidget);
      await tester.tap(button);
      await tester.pump(const Duration(seconds: 2));
      expect(find.text("Help"), findsOneWidget);
      await tester.pump(const Duration(seconds: 2));
    },
  );
}

Error

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5021 pos 12:
'entry.currentState == _RouteLifecycle.popping ||
          (entry.hasPage && entry.currentState.index < _RouteLifecycle.pop.index)': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  [https://github.com/flutter/flutter/issues/new?template=2_bug.md]()

When the exception was thrown, this was the stack:
#2      NavigatorState.finalizeRoute (package:flutter/src/widgets/navigator.dart:5021:12)
#3      OverlayRoute.didPop (package:flutter/src/widgets/routes.dart:74:18)
#4      FlushbarRoute.didPop (package:another_flushbar/flushbar_route.dart:393:18)
#5      _RouteEntry.handlePop (package:flutter/src/widgets/navigator.dart:2896:16)
#6      NavigatorState._flushHistoryUpdates (package:flutter/src/widgets/navigator.dart:3860:22)
#7      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:4902:7)
#8      FlushbarRoute._configureTimer.<anonymous closure> (package:another_flushbar/flushbar_route.dart:403:22)
#15     FakeTimer._fire (package:fake_async/fake_async.dart:316:16)
#16     FakeAsync._fireTimersWhile (package:fake_async/fake_async.dart:240:13)
#17     FakeAsync.elapse (package:fake_async/fake_async.dart:137:5)
#18     AutomatedTestWidgetsFlutterBinding.pump.<anonymous closure> (package:flutter_test/src/binding.dart:986:28)
#21     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#22     AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:982:27)
#23     WidgetTester.pump.<anonymous closure> (package:flutter_test/src/widget_tester.dart:608:53)
#26     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#27     WidgetTester.pump (package:flutter_test/src/widget_tester.dart:608:27)
#28     main.<anonymous closure> ([file:///C:/projects/flutter/trainingsmagnet/test/example/flush_example_test.dart:22:20]())
<asynchronous suspension>
<asynchronous suspension>
(elided 13 frames from class _AssertionError, dart:async, and package:stack_trace)

The test description was:
  test flushbar
════════════════════════════════════════════════════════════════════════════════════════════════════

Remove the Duration property in the widget and it works fine.

devmobile-vulog commented 2 years ago

We are encountering the same issue with flutter 2.10.3 and another_flushbar: 1.10.28

ortemmetro commented 10 months ago

Any updates on this?