Skip to content

Commit

Permalink
#6 - NoAnimationPage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalabaster committed Dec 28, 2023
1 parent e7babe9 commit d14f090
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
5 changes: 5 additions & 0 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class MyApp extends StatelessWidget {
),
enabled: enabled,
backgroundLockLatency: backgroundLockLatency,
inactiveBuilder: (context) => const Scaffold(
body: Center(
child: FlutterLogo(size: 80),
),
),
),
home: const MyHomePage(
key: Key('MyHomePage'),
Expand Down
16 changes: 13 additions & 3 deletions lib/src/app_lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_app_lock/src/no_animation_page.dart';

/// A widget which handles app lifecycle events for showing and hiding a lock screen.
/// This should wrap around a `MyApp` widget (or equivalent).
Expand Down Expand Up @@ -111,11 +112,20 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
onPopPage: (route, result) => route.didPop(result),
pages: [
if (_didUnlockForAppLaunch)
MaterialPage(child: widget.builder(context, _launchArg)),
MaterialPage(
key: const ValueKey('App'),
child: widget.builder(context, _launchArg),
),
if (_locked)
MaterialPage(child: _lockScreen)
MaterialPage(
key: const ValueKey('LockScreen'),
child: _lockScreen,
)
else if (_inactive && widget.inactiveBuilder != null)
MaterialPage(child: widget.inactiveBuilder!(context)),
NoAnimationPage(
key: const ValueKey('InactiveScreen'),
child: widget.inactiveBuilder!(context),
),
],
);
}
Expand Down
57 changes: 57 additions & 0 deletions lib/src/no_animation_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';

class NoAnimationPage<T> extends Page<T> {
const NoAnimationPage({
required this.child,
this.maintainState = true,
this.fullscreenDialog = false,
this.allowSnapshotting = true,
super.key,
super.name,
super.arguments,
super.restorationId,
});

final Widget child;
final bool maintainState;
final bool fullscreenDialog;
final bool allowSnapshotting;

@override
Route<T> createRoute(BuildContext context) => _NoAnimationPageRoute<T>(
page: this, allowSnapshotting: allowSnapshotting);
}

class _NoAnimationPageRoute<T> extends PageRoute<T> {
_NoAnimationPageRoute({
required NoAnimationPage<T> page,
super.allowSnapshotting,
}) : super(settings: page) {
assert(opaque);
}

NoAnimationPage<T> get _page => settings as NoAnimationPage<T>;

@override
bool get maintainState => _page.maintainState;

@override
bool get fullscreenDialog => _page.fullscreenDialog;

@override
String get debugLabel => '${super.debugLabel}(${_page.name})';

@override
Color? get barrierColor => null;

@override
String? get barrierLabel => null;

@override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) =>
_page.child;

@override
Duration get transitionDuration => Duration.zero;
}

0 comments on commit d14f090

Please sign in to comment.