Skip to content

Commit

Permalink
fix router example
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Sep 18, 2024
1 parent 3b7f86e commit 78d1bb6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app_widget/lib/src/snack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
Future<void> muiSnack(BuildContext context, String message) async {
// ignore: avoid_print
print('snack: $message');
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text(message),
));
if (context.mounted) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text(message),
));
}
}
94 changes: 93 additions & 1 deletion example/navigator_test_app_lib/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,99 @@
import 'package:flutter/material.dart';
import 'package:tekartik_app_flutter_widget/mini_ui.dart';
import 'package:tekartik_app_navigator_flutter/content_navigator.dart';
import 'package:tekartik_test_menu_flutter/test.dart';

void defineNavigatorMenu() {
menu('navigator', () {
item('list assets', () async {});
item('run app with navigator', () async {
contentNavigatorDebug = true;
runAppWithNavigator();
});
});
}

Future<void> _pushPage1(BuildContext context) async {
var result = await ContentNavigator.of(muiBuildContext)
.pushPath<Object?>(Page1ContentPath());
// ignore: use_build_context_synchronously
await muiSnack(muiBuildContext, 'push Page 1 result: $result');
}

var pageStartDef = ContentPageDef(
path: rootContentPath,
screenBuilder: (_) {
return muiScreenWidget('Start', () {
muiItem('push Page 1', () async {
await _pushPage1(muiBuildContext);
});
});
});
var page1Def = ContentPageDef(
path: Page1ContentPath(),
screenBuilder: (_) {
return muiScreenWidget('Page 1', () {
muiItem('push Page 2', () async {
var result = await ContentNavigator.of(muiBuildContext)
.pushPath<Object?>(Page2ContentPath());
// ignore: use_build_context_synchronously
await muiSnack(muiBuildContext, 'push Page 2 result: $result');
});
muiItem('pop', () {
Navigator.of(muiBuildContext).pop();
});
});
});
var page2Def = ContentPageDef(
path: Page2ContentPath(),
screenBuilder: (_) {
return muiScreenWidget('Page 2', () {
muiItem('pop', () {
Navigator.of(muiBuildContext).pop();
});
muiItem('pop to root', () {
Navigator.of(muiBuildContext).popUntilPath(rootContentPath);
});
muiItem('pop all', () {
ContentNavigator.of(muiBuildContext).transientPopAll();
});
muiItem('pop to root push page 1', () async {
Navigator.of(muiBuildContext).popUntilPath(rootContentPath);
await _pushPage1(muiBuildContext);
});
muiItem('pop all push page 1', () async {
ContentNavigator.of(muiBuildContext).transientPopAll();
await _pushPage1(muiBuildContext);
});
});
});

class Page1ContentPath extends ContentPathBase {
final part = ContentPathPart('page1');

@override
List<ContentPathField> get fields => [part];
}

class Page2ContentPath extends ContentPathBase {
final part = ContentPathPart('page2');

@override
List<ContentPathField> get fields => [part];
}

var contentNavigatorDef =
ContentNavigatorDef(defs: [pageStartDef, page1Def, page2Def]);
void runAppWithNavigator() {
runApp(ContentNavigator(
def: contentNavigatorDef,
child: Builder(builder: (context) {
var cn = ContentNavigator.of(context);
return MaterialApp.router(
debugShowCheckedModeBanner: false,
title: 'Navigator',
//navigatorObservers: [cn.routeObserver],
routerDelegate: cn.routerDelegate,
routeInformationParser: cn.routeInformationParser,
);
})));
}
8 changes: 8 additions & 0 deletions example/navigator_test_app_lib/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ dependencies:
ref: dart3a
path: test_menu_flutter
version: '>=0.2.3'
tekartik_app_flutter_widget:
git:
url: https://github.com/tekartik/app_flutter_utils.dart
ref: dart3a
path: app_widget
version: '>=0.2.1'

dev_dependencies:
flutter_test:
sdk: flutter


dependency_overrides:
tekartik_app_flutter_widget:
path: ../../app_widget
tekartik_app_navigator_flutter:
path: ../../app_navigator
flutter:
Expand Down

0 comments on commit 78d1bb6

Please sign in to comment.