-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: zoom entire home screen on push route
- Loading branch information
1 parent
0c05024
commit 5ee8086
Showing
8 changed files
with
109 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:shiritori/app/app.dart'; | ||
|
||
import 'assets/assets.dart'; | ||
|
||
void main() async { | ||
log('Initializing binding...'); | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
log('Loading background image...'); | ||
final backgroundImage = await Images.loadBackground(); | ||
log('Initialization done.'); | ||
runApp(AppRoot(backgroundImage: backgroundImage)); | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1 +1 @@ | ||
export 'background.dart'; | ||
export 'zoom_container.dart'; |
This file contains 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 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 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 |
---|---|---|
@@ -1,56 +1,108 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
class RouteNotifier<R extends ModalRoute> extends NavigatorObserver { | ||
void Function(Route route, Route previousRoute) _didPop; | ||
void Function(Route route, Route previousRoute) _didPush; | ||
void Function(Route route, Route previousRoute) _didRemove; | ||
void Function({Route newRoute, Route oldRoute}) _didReplace; | ||
final _listeners = <RouteNotifierListener>[]; | ||
|
||
@override | ||
void didPop(Route route, Route previousRoute) { | ||
if (route is R || previousRoute is R) { | ||
_didPop?.call(route, previousRoute); | ||
for (final listener in _listeners) { | ||
listener.didPop?.call(route, previousRoute); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void didPush(Route route, Route previousRoute) { | ||
if (route is R || previousRoute is R) { | ||
_didPush?.call(route, previousRoute); | ||
for (final listener in _listeners) { | ||
listener.didPush?.call(route, previousRoute); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void didRemove(Route route, Route previousRoute) { | ||
if (route is R || previousRoute is R) { | ||
_didRemove?.call(route, previousRoute); | ||
for (final listener in _listeners) { | ||
listener.didRemove?.call(route, previousRoute); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void didReplace({Route newRoute, Route oldRoute}) { | ||
if (newRoute is R || oldRoute is R) { | ||
_didReplace?.call(newRoute: newRoute, oldRoute: oldRoute); | ||
for (final listener in _listeners) { | ||
listener.didReplace?.call(newRoute: newRoute, oldRoute: oldRoute); | ||
} | ||
} | ||
} | ||
} | ||
|
||
mixin RouteNotifierStateMixin<R extends ModalRoute, T extends StatefulWidget> | ||
on State<T> { | ||
RouteNotifierListener<R> _listener; | ||
|
||
RouteNotifier<R> get routeNotifier; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
routeNotifier._didPop = didPop; | ||
routeNotifier._didPush = didPush; | ||
routeNotifier._didRemove = didRemove; | ||
routeNotifier._didReplace = didReplace; | ||
_listener = RouteNotifierListener<R>( | ||
didPop: didPop, | ||
didPush: didPush, | ||
didRemove: didRemove, | ||
didReplace: didReplace, | ||
); | ||
routeNotifier._listeners.add(_listener); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
if (_listener != null) { | ||
routeNotifier._listeners.remove(_listener); | ||
} | ||
super.dispose(); | ||
} | ||
|
||
void didPop(Route route, Route previousRoute); | ||
void didPush(Route route, Route previousRoute); | ||
void didRemove(Route route, Route previousRoute); | ||
void didReplace({Route newRoute, Route oldRoute}); | ||
} | ||
|
||
@immutable | ||
class RouteNotifierListener<R extends ModalRoute> { | ||
const RouteNotifierListener({ | ||
this.didPop, | ||
this.didPush, | ||
this.didRemove, | ||
this.didReplace, | ||
}); | ||
|
||
final void Function(Route route, Route previousRoute) didPop; | ||
final void Function(Route route, Route previousRoute) didPush; | ||
final void Function(Route route, Route previousRoute) didRemove; | ||
final void Function({Route newRoute, Route oldRoute}) didReplace; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) { | ||
return true; | ||
} | ||
|
||
return other is RouteNotifierListener<R> && | ||
other.didPop == didPop && | ||
other.didPush == didPush && | ||
other.didRemove == didRemove && | ||
other.didReplace == didReplace; | ||
} | ||
|
||
@override | ||
int get hashCode => | ||
didPop.hashCode ^ | ||
didPush.hashCode ^ | ||
didRemove.hashCode & didReplace.hashCode; | ||
} |