Giter VIP home page Giter VIP logo

wizard_router's People

Contributors

carlosnihelton avatar chillbrodev avatar d-loose avatar github-actions[bot] avatar jpnurmi avatar osomon avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wizard_router's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yaml
  • actions/checkout v3
  • subosito/flutter-action v2
  • actions/checkout v3
  • subosito/flutter-action v2
  • codecov/codecov-action v3
  • actions/checkout v3
  • subosito/flutter-action v2
  • actions/checkout v3
  • subosito/flutter-action v2
  • actions/checkout v3
  • subosito/flutter-action v2
  • actions/checkout v3
  • subosito/flutter-action v2
  • actions/checkout v3
  • subosito/flutter-action v2
.github/workflows/pr.yaml
.github/workflows/release.yaml
pub
example/pubspec.yaml
  • flutter_markdown ^0.6.2
  • provider ^6.0.0
  • flutter_lints ^2.0.0
pubspec.yaml
  • collection ^1.15.0
  • flow_builder ^0.0.9
  • safe_change_notifier ^0.3.0
  • flutter_lints ^2.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

hasNext getter is misleading for dynamically set wizards

By dynamically set I mean wizards that skip certain routes, like when we set the inital route to other than the first element of the routes map. In such cases the widget._index counts the number of routes that we actually passed by (not counting the ones we skipped), thus the comparison returns true even for the last element of the routes map.

  /// Returns `false` if the wizard page is the last page.
  bool get hasNext => widget._index < widget._routes.length - 1;

The test case below demonstrate the behavior reported. It consists with three routes, where the second is set as initial. The third (and last) route checks for Wizard.of(context).hasNext, but that is not enough to prevent calling next() from the last route, thus causing an assertion failure.

  testWidgets('hasNext returns false for the last route', (tester) async {
    await pumpWizardApp(
      tester,
      initialRoute: Routes.second,
      routes: {
        Routes.first: WizardRoute(builder: (_) => const Text(Routes.first)),
        Routes.second: WizardRoute(
          builder: (context) => ElevatedButton(
              child: Text(Routes.second), onPressed: Wizard.of(context).next),
        ),
        Routes.third: WizardRoute(
          builder: (context) => TextButton(
            child: Text(Routes.third),
            onPressed: () {
              final wiz = Wizard.of(context);
              // Third should never call next() because it's the last route.
              if (wiz.hasNext) wiz.next();
            },
          ),
        ),
      },
    );

    // We are on the second route.
    await tester.tap(find.byType(ElevatedButton));
    await tester.pumpAndSettle();

    //Now we should be on the third
    expect(find.text(Routes.first), findsNothing);
    expect(find.text(Routes.second), findsNothing);
    expect(find.text(Routes.third), findsOneWidget);

    // Nothing should happen now:
    await tester.tap(find.byType(TextButton));
    await tester.pumpAndSettle();

    expect(find.text(Routes.first), findsNothing);
    expect(find.text(Routes.second), findsNothing);
    expect(find.text(Routes.third), findsOneWidget);
  });
00:02 +3: hasNext should return false for the last route
══╡ EXCEPTION CAUGHT BY GESTURE ╞══════════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
`Wizard.next()` called from the last route /third.
'package:wizard_router/src/scope.dart':
Failed assertion: line 103 pos 14: 'index < widget._routes.length - 1'


The solution is baked inside the WizardScope.next() method. Unfortunately that will make the hasNext getter to be more expensive.

WizardController could be disposed during asynchronous callbacks

If the controller has been disposed when the execution returns from an asynchronous callback, it must not call ChangeNotifier.notifyListeners() which throws if already disposed...

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test (but after the test had completed):
A WizardController was used after being disposed.
Once you have called dispose() on a WizardController, it can no longer be used.

When the exception was thrown, this was the stack:
#0      ChangeNotifier.debugAssertNotDisposed.<anonymous closure> (package:flutter/src/foundation/change_notifier.dart:179:9)
#1      ChangeNotifier.debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:186:6)
#2      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:382:27)
#3      WizardController._loadRoute (package:wizard_router/src/controller.dart:30:28)
2
<asynchronous suspension>
(elided one frame from package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════

This is the classic reason why we're using safe_change_notifier all around but I'm not sure if we want to pull it as a dependency here...

Add WizardObserver and Wizard.done()

Idea:

  • add WizardObserver that wraps NavigatorObserver and offers next/back/done instead of push/pop operations
  • app calls Wizard.of(context).done() from any page where the wizard ends
  • WizardScopeState.done() merely calls Wizard.onDone() and WizardObserver.onDone()
  • done() could optionally accept a result arg

Motivation:

  • provides an easy way to pass control from the last page to a central place for e.g. tear-down routines
  • as for the desktop installer, it could call Wizard.done() in all last pages and TelemetryService.done() could be called from one place i.e. the observer

Imported from canonical/ubuntu-flutter-plugins#31

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.