Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
remove Wizard.done()
Browse files Browse the repository at this point in the history
  • Loading branch information
d-loose committed Apr 27, 2023
1 parent ebb2df6 commit 5366767
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 87 deletions.
7 changes: 0 additions & 7 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ enum WizardControllerAction {
back,
next,
replace,
done,
unknown,
}

Expand All @@ -33,12 +32,6 @@ class WizardController extends ChangeNotifier {
notifyListeners();
}

void done({Object? result}) {
action = WizardControllerAction.done;
arguments = result;
notifyListeners();
}

void replace({Object? arguments}) {
action = WizardControllerAction.replace;
this.arguments = arguments;
Expand Down
5 changes: 0 additions & 5 deletions lib/src/observer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:flutter/widgets.dart';

/// An interface for observing the behavior of a [Wizard].
Expand All @@ -12,7 +10,4 @@ class WizardObserver {

/// The wizard moved to [route] from [previousRoute].
void onNext(Route route, Route previousRoute) {}

/// The wizard was done at [route].
FutureOr<void> onDone(Route route, Object? result) {}
}
9 changes: 0 additions & 9 deletions lib/src/route.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import 'dart:async';

import 'package:flutter/widgets.dart';

/// The signature of [WizardRoute.onNext] and [WizardRoute.onBack] callbacks.
typedef WizardRouteCallback = String? Function(RouteSettings settings);

/// The signature of [WizardRoute.onDone] callback.
typedef WizardDoneCallback = FutureOr<void> Function(Object? result);

class WizardRoute {
const WizardRoute({
required this.builder,
this.onNext,
this.onReplace,
this.onBack,
this.onDone,
this.userData,
});

Expand All @@ -38,9 +32,6 @@ class WizardRoute {
/// from [routes].
final WizardRouteCallback? onBack;

/// The callback invoked when the wizard is done.
final WizardDoneCallback? onDone;

/// Additional custom data associated with this page.
final Object? userData;
}
32 changes: 0 additions & 32 deletions lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flow_builder/flow_builder.dart';
import 'package:flutter/widgets.dart';

import 'controller.dart';
import 'result.dart';
import 'route.dart';
import 'settings.dart';

Expand Down Expand Up @@ -165,31 +164,6 @@ class WizardScopeState extends State<WizardScope> {
});
}

/// Sets the wizard done. Optionally, a `result` can be passed to the route.
///
/// ```dart
/// onPressed: Wizard.of(context).done
/// ```
FutureOr<void> done({Object? result}) async {
final routes = _getRoutes();
assert(routes.isNotEmpty, routes.length.toString());

final flow = context.flow<List<WizardRouteSettings>>();

await widget._route.onDone?.call(result);

flow.complete((state) {
final copy = List<WizardRouteSettings>.of(state);
final settings = copy.removeLast();
return copy
..add(WizardRouteResult(
settings,
result: result,
route: ModalRoute.of(context)!,
));
});
}

List<WizardRouteSettings> _getRoutes() =>
context.flow<List<WizardRouteSettings>>().state;

Expand All @@ -210,9 +184,6 @@ class WizardScopeState extends State<WizardScope> {
return previousIndex < widget._routes.length - 1;
}

/// Returns `true` if the wizard is done.
bool get isDone => context.flow<List<WizardRouteSettings>>().completed;

Object? get routeData => widget._route.userData;
Object? get wizardData => widget._userData;

Expand All @@ -231,9 +202,6 @@ class WizardScopeState extends State<WizardScope> {
case WizardControllerAction.replace:
replace(arguments: widget._controller?.arguments);
break;
case WizardControllerAction.done:
done(result: widget._controller?.arguments);
break;
case null:
case WizardControllerAction.unknown:
debugPrint('Wizard does not know how to handle null or unknown action');
Expand Down
9 changes: 0 additions & 9 deletions lib/src/wizard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';

import 'controller.dart';
import 'observer.dart';
import 'result.dart';
import 'route.dart';
import 'scope.dart';
import 'settings.dart';
Expand Down Expand Up @@ -148,7 +147,6 @@ class Wizard extends StatefulWidget {
/// - [WizardScopeState.replace]
/// - [WizardScopeState.back]
/// - [WizardScopeState.home]
/// - [WizardScopeState.done]
static WizardScopeState of(BuildContext context, {bool root = false}) {
final scope = maybeOf(context, root: root);
assert(() {
Expand Down Expand Up @@ -176,7 +174,6 @@ class Wizard extends StatefulWidget {
/// - [WizardScopeState.replace]
/// - [WizardScopeState.back]
/// - [WizardScopeState.home]
/// - [WizardScopeState.done]
static WizardScopeState? maybeOf(BuildContext context, {bool root = false}) {
return root
? context.findRootAncestorStateOfType<WizardScopeState>()
Expand Down Expand Up @@ -244,12 +241,6 @@ class _WizardState extends State<Wizard> {
.toList();
},
observers: [_WizardFlowObserver(widget.observers), HeroController()],
onComplete: (state) async {
final result = state.lastOrNull as WizardRouteResult;
for (final observer in widget.observers) {
await observer.onDone(result.route, result.result);
}
},
);
}
}
Expand Down
25 changes: 0 additions & 25 deletions test/wizard_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class TestObserver extends WizardObserver {
Route? nextFrom;
Route? backTo;
Route? backFrom;
Route? done;
Object? result;

void reset() {
Expand All @@ -25,7 +24,6 @@ class TestObserver extends WizardObserver {
nextFrom = null;
backTo = null;
backFrom = null;
done = null;
result = null;
}

Expand All @@ -45,12 +43,6 @@ class TestObserver extends WizardObserver {
backTo = route;
backFrom = previousRoute;
}

@override
void onDone(Route route, Object? res) {
done = route;
result = res;
}
}

void main() {
Expand Down Expand Up @@ -603,7 +595,6 @@ void main() {
expect(observer.nextTo, isNull);
expect(observer.backFrom, isNull);
expect(observer.backTo, isNull);
expect(observer.done, isNull);
observer.reset();

Wizard.of(tester.element(find.text(Routes.first))).next();
Expand All @@ -614,7 +605,6 @@ void main() {
expect(observer.backFrom, isNull);
expect(observer.backTo, isNull);
expect(observer.init, isNull);
expect(observer.done, isNull);
observer.reset();

Wizard.of(tester.element(find.text(Routes.second))).replace();
Expand All @@ -625,7 +615,6 @@ void main() {
expect(observer.backFrom, isNull);
expect(observer.backTo, isNull);
expect(observer.init, isNull);
expect(observer.done, isNull);
observer.reset();

Wizard.of(tester.element(find.text(Routes.third))).back();
Expand All @@ -636,20 +625,6 @@ void main() {
expect(observer.nextFrom, isNull);
expect(observer.nextTo, isNull);
expect(observer.init, isNull);
expect(observer.done, isNull);
observer.reset();

Wizard.of(tester.element(find.text(Routes.first))).done(result: 'done');
await tester.pumpAndSettle();

expect(observer.done, isNotNull);
expect(observer.done!.settings.name, Routes.first);
expect(observer.result, 'done');
expect(observer.nextFrom, isNull);
expect(observer.nextTo, isNull);
expect(observer.backFrom, isNull);
expect(observer.backTo, isNull);
expect(observer.init, isNull);
observer.reset();
});

Expand Down

0 comments on commit 5366767

Please sign in to comment.