Building Complex UI in Flutter: Magic 8-Ball
Learn how to build complex user interfaces in Flutter by creating a nearly 3D Magic 8-Ball using standard Flutter components. By Nic Ford.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Building Complex UI in Flutter: Magic 8-Ball
35 mins
- Getting Started
- Creating Novel User Experiences: Beyond Material and Cupertino
- Understanding 2.5D
- Understanding Neumorphic Design
- Building the Magic 8-Ball in Flutter
- Understanding the Difference That Lighting Can Make
- Understanding Coordinate Systems
- Using a Command-and-Control Widget
- Understanding the Glorious Offset Class
- Understanding Matrix4 Transformations and the Three Axes
- Adding a Shadow of Doubt
- Using the Transform Widget
- Adding the Prediction
- Getting Things Moving
- Setting the Rest Position
- Responding to Gestures
- Warping the Window
- Adding Animations
- Moving the Window
- Having Fun with Curves
- Fading the Prediction
- Where to Go From Here?
Fading the Prediction
Finally, fade Prediction
out while it’s being dragged and change its angle on release so that it comes back slightly askew, just like real-world 8-balls.
Add and update an angle of wobble field:
double wobble = 0.0;
...
void _end() {
...
wobble = rand.nextDouble() * (wobble.isNegative ? 0.5 : -0.5);
...
}
wobble
is in the range -0.5 to 0.5 radians, roughly -30° to +30°. Checking negativity allows you to invert the sign on each new prediction, making the wobble clockwise then counter-clockwise in turn.
Surround Prediction
with Transform
and Opacity
widgets that vary according to the controller:
child: Opacity(
opacity: 1 - controller.value, // fading out when moving
child: Transform.rotate( // convenience method for `rotateZ`
angle: wobble,
child: Prediction(text: prediction)
)
)
Save. Drag. See the future predicted.
Where to Go From Here?
Congratulations on completing the tutorial!
You can download the final project using the Download Materials button at the top or bottom of this tutorial. From here, you can run and install the finished version of the app and browse around the finished project to see all the code.
You’ve really only touched the surface of what 2.5D design can do. Play with Gradient
s and Offset
s, or if you’re feeling really enthused, delve into Matrix4
transformations.
We hope you enjoyed this tutorial — thanks for reading! If you have any questions or comments, please join the forum discussion below.