-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/deep linking #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7984997
Migrate to Router
DeD1rk 68ace4e
Fix forgotten login screen use of Navigator
DeD1rk ae40fb9
Fix null problem on logout
DeD1rk 7eb09c7
Add Deep Linking, doesn't seem to work yet
DeD1rk ec21f82
Add android Deep Linking config, still not working right
DeD1rk c641cdb
Make deeplinking work on ios
DeD1rk 95713c9
Migrate deprecated stuff after flutter 2.0
DeD1rk 7275df9
Enable replacing the navigation stack
DeD1rk c823f71
Finish deep linking
DeD1rk fffe85e
Merge branch 'master' into feature/deep-linking
DeD1rk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:provider/provider.dart'; | ||
| import 'package:reaxit/providers/auth_provider.dart'; | ||
| import 'package:reaxit/ui/screens/album_detail.dart'; | ||
| import 'package:reaxit/ui/screens/album_list.dart'; | ||
| import 'package:reaxit/ui/screens/calendar_screen.dart'; | ||
| import 'package:reaxit/ui/screens/event_screen.dart'; | ||
| import 'package:reaxit/ui/screens/login_screen.dart'; | ||
| import 'package:reaxit/ui/screens/pizza_screen.dart'; | ||
| import 'package:reaxit/ui/screens/welcome_screen.dart'; | ||
|
|
||
| class ThaliaRouterDelegate extends RouterDelegate<List<Page>> | ||
| with ChangeNotifier, PopNavigatorRouterDelegateMixin<List<Page>> { | ||
| final GlobalKey<NavigatorState> navigatorKey; | ||
|
|
||
| static ThaliaRouterDelegate of(BuildContext context) { | ||
| RouterDelegate delegate = Router.of(context).routerDelegate; | ||
| assert(delegate is ThaliaRouterDelegate, 'Delegate type must match.'); | ||
| return delegate as ThaliaRouterDelegate; | ||
| } | ||
|
|
||
| ThaliaRouterDelegate() : navigatorKey = GlobalKey<NavigatorState>(); | ||
|
|
||
| List<Page> _stack = [MaterialPage(child: WelcomeScreen())]; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Consumer<AuthProvider>( | ||
| builder: (context, auth, child) { | ||
| if (auth.status == AuthStatus.SIGNED_OUT) { | ||
| _stack | ||
| ..clear() | ||
| ..add(MaterialPage(child: LoginScreen())); | ||
| } | ||
|
|
||
| return Navigator( | ||
| key: navigatorKey, | ||
| onPopPage: _onPopPage, | ||
| pages: auth.status == AuthStatus.INIT | ||
| ? [MaterialPage(child: _SplashScreen())] | ||
| : _stack.toList(), | ||
| ); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| bool _onPopPage(route, result) { | ||
| if (!route.didPop(result)) return false; | ||
| if (_stack.length > 1) _stack.removeLast(); | ||
| notifyListeners(); | ||
| return true; | ||
| } | ||
|
|
||
| @override | ||
| Future<void> setNewRoutePath(List<Page> stack) async { | ||
| _stack | ||
| ..clear() | ||
| ..addAll(stack); | ||
| return SynchronousFuture(null); | ||
| } | ||
|
|
||
| /// Adds a page to the top of the stack. | ||
| void push(Page page) { | ||
| _stack.add(page); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| /// Removes the top of the stack. | ||
| void pop() { | ||
| if (_stack.length > 1) _stack.removeLast(); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| /// Replaces the top of the stack. | ||
| void replace(Page page) { | ||
| _stack | ||
| ..removeLast() | ||
| ..add(page); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| /// Replaces the current stack. | ||
| void replaceStack(List<Page> stack) { | ||
| _stack | ||
| ..clear() | ||
| ..addAll(stack); | ||
| notifyListeners(); | ||
| } | ||
| } | ||
|
|
||
| class _SplashScreen extends StatelessWidget { | ||
| const _SplashScreen({ | ||
| Key key, | ||
| }) : super(key: key); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Container( | ||
| color: Color(0xFFE62272), | ||
| child: Center( | ||
| child: CircularProgressIndicator( | ||
| valueColor: AlwaysStoppedAnimation<Color>(Colors.white), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class ThaliaRouteInformationParser | ||
| implements RouteInformationParser<List<Page>> { | ||
| @override | ||
| Future<List<Page>> parseRouteInformation(routeInformation) async { | ||
| Uri uri = Uri.parse(routeInformation.location); | ||
| String path = uri.path; | ||
| List<String> segments = uri.pathSegments; | ||
|
|
||
| // Handle "/". | ||
| if (uri.pathSegments.length == 0) | ||
| return [MaterialPage(child: WelcomeScreen())]; | ||
|
|
||
| if (RegExp('^/pizzas/\$').hasMatch(path)) { | ||
| return [ | ||
| MaterialPage(child: WelcomeScreen()), | ||
| MaterialPage(child: PizzaScreen()), | ||
| ]; | ||
| } else if (RegExp('^/events/\$').hasMatch(path)) { | ||
| return [MaterialPage(child: CalendarScreen())]; | ||
| } else if (RegExp('^/events/([0-9]+)/\$').hasMatch(path)) { | ||
| return [ | ||
| MaterialPage(child: CalendarScreen()), | ||
| MaterialPage(child: EventScreen(int.parse(segments[1]))) | ||
| ]; | ||
| } else if (RegExp('^/members/photos/([0-9]+)/\$').hasMatch(path)) { | ||
| return [ | ||
| MaterialPage(child: AlbumList()), | ||
| MaterialPage(child: AlbumDetail(int.parse(segments[1]))) | ||
| ]; | ||
| } | ||
|
|
||
| // Handle unknown path. | ||
| return [MaterialPage(child: WelcomeScreen())]; | ||
| } | ||
|
|
||
| @override | ||
| RouteInformation restoreRouteInformation(configuration) { | ||
| return RouteInformation(location: "/"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.