warmup_routine
a library for handling animation warmup generically
update:
the ios jank issue relating to shader warmup is now largely mitigated by shader pre-compilation as described here. huge thanks to the flutter team!
warmup_routine
a library for handling animation warmup generically as discussed in: https://github.com/flutter/flutter/issues/76180
this solution is not very scalable for applications with many animations to warm up and is meant mostly as an example of an approach applications could take to warmup their animations until a more permanent solution is available.
usage
warmup overlay
the most common way to warmup animations is to use a pseudo splash screen that executes the animations while the application is starting up.
import 'package:warmup_routine/warmup_overlay.dart';
import 'package:warmup_routine/warmup_animation.dart';
// example of showing an overlay under which the animations are executing.
class warmupoverlayexample extends statefulwidget {
_warmupoverlayexamplestate createstate() => _warmupoverlayexamplestate();
}
class _warmupoverlayexamplestate extends state<warmupoverlayexample> {
bool _shouldshowoverlay = true;
@override
widget build(buildcontext context) {
if (_shouldshowoverlay) {
return warmupoverlay(
oncomplete: () {
setstate(() {
_shouldshowoverlay = false;
});
},
builder: (context) {
return container(
child: center(
child: circularprogressindicator(),
),
);
},
animations: [
warmupanimation(
builder: (context, complete) {
// replace with your animation of choice
return opencontaineranimation(oncomplete: complete);
},
repeat: 4,
),
],
);
}
} else {
// start rest of application
myapp();
}
}
warmup routine
if an overlay is not desired, a warmup routine can be executed anywhere in your existing directly:
class warmuproutineexample extends statelesswidget {
@override
widget build(buildcontext context) {
return warmuproutine(
animations: [
warmupanimation(
builder: (context, complete) {
// replace with your animation of choice
return opencontaineranimation(oncomplete: complete);
},
repeat: 4,
),
],
oncomplete: () {
// start rest of application
},
);
}
}
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
Comments are closed.