Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
danReynolds committed Mar 1, 2021
1 parent a1b4960 commit 9f54e95
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 2 deletions.
80 changes: 79 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,82 @@ class WarmupRoutineExample extends StatelessWidget {
}
```

Full example in [GitHub repo](https://github.com/danReynolds/warmup_routine/blob/master/example.dart)
### Navigator example

```
// The overlay will remain on top of the application above navigation events, so Navigator.push/pop
// can be warmed up as well:
class NavigationWarmupScreen extends StatefulWidget {
final Function onComplete;
NavigationWarmupScreen({@required this.onComplete});
_NavigationWarmupScreenState createState() => _NavigationWarmupScreenState();
}
class _NavigationWarmupScreenState extends State<NavigationWarmupScreen> {
initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) {
return YourWidget();
},
fullscreenDialog: true,
),
);
Future.delayed(
// Adjust duration as needed
Duration(milliseconds: 400),
() {
Navigator.pop(context);
Future.delayed(
Duration(milliseconds: 400),
() {
widget.onComplete();
},
);
},
);
});
}
@override
build(context) {
return Container();
}
}
class WarmupOverlayNavigationExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return WarmupOverlay(
onComplete: () {
// Start rest of application
},
builder: (context) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
},
animations: [
WarmupAnimation(
builder: (context, complete) {
return NavigationWarmupScreen(onComplete: complete);
},
repeat: 2,
),
],
);
}
}
```

Full examples in [GitHub repo](https://github.com/danReynolds/warmup_routine/blob/master/example.dart)
77 changes: 77 additions & 0 deletions example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class _OpenContainerAnimationState extends State<OpenContainerAnimation> {
}
}

// Example of showing an overlay under which the animations are executing.
class WarmupOverlayExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -99,6 +100,8 @@ class WarmupOverlayExample extends StatelessWidget {
}
}

// If an overlay is not desired, warmup animations can be executed directly
// with the WarmupRoutine widget
class WarmupRoutineExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand All @@ -118,3 +121,77 @@ class WarmupRoutineExample extends StatelessWidget {
);
}
}

// The overlay will remain on top of the application above navigation events, so Navigator.push/pop
// can be warmed up as well:

class NavigationWarmupScreen extends StatefulWidget {
final Function onComplete;

NavigationWarmupScreen({@required this.onComplete});

_NavigationWarmupScreenState createState() => _NavigationWarmupScreenState();
}

class _NavigationWarmupScreenState extends State<NavigationWarmupScreen> {
initState() {
super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) {
return YourWidget();
},
fullscreenDialog: true,
),
);

Future.delayed(
// Adjust duration as needed
Duration(milliseconds: 400),
() {
Navigator.pop(context);
Future.delayed(
Duration(milliseconds: 400),
() {
widget.onComplete();
},
);
},
);
});
}

@override
build(context) {
return Container();
}
}

class WarmupOverlayNavigationExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return WarmupOverlay(
onComplete: () {
// Start rest of application
},
builder: (context) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
},
animations: [
WarmupAnimation(
builder: (context, complete) {
return NavigationWarmupScreen(onComplete: complete);
},
repeat: 2,
),
],
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: warmup_routine
description: A general purpose wrapper for warming up animations.
version: 0.0.4
version: 0.0.6
homepage: https://github.com/danReynolds/warmup_routine

environment:
Expand Down

0 comments on commit 9f54e95

Please sign in to comment.