Book Image

Flutter Projects

By : Simone Alessandria
Book Image

Flutter Projects

By: Simone Alessandria

Overview of this book

Flutter is a modern reactive mobile framework that removes a lot of the complexity found in building native mobile apps for iOS and Android. With Flutter, developers can now build fast and native mobile apps from a single codebase. This book is packed with 11 projects that will help you build your own mobile applications using Flutter. It begins with an introduction to Dart programming and explains how it can be used with the Flutter SDK to customize mobile apps. Each chapter contains instructions on how to build an independent app from scratch, and each project focuses on important Flutter features.From building Flutter Widgets and applying animations to using databases (SQLite and sembast) and Firebase, you'll build on your knowledge through the chapters. As you progress, you’ll learn how to connect to remote services, integrate maps, and even use Flare to create apps and games in Flutter. Gradually, you’ll be able to create apps and games that are ready to be published on the Google Play Store and the App Store. In the concluding chapters, you’ll learn how to use the BLoC pattern and various best practices related to creating enterprise apps with Flutter. By the end of this book, you will have the skills you need to write and deliver fully functional mobile apps using Flutter.
Table of Contents (15 chapters)
12
Assessment

Adding randomness to the game

One of the basic ingredients that make a game interesting is the random element. There are two moments in our game where we can add some randomness. One is the bouncing angle: it doesn't need to be exactly 45 degrees each time it bounces. Making the bouncing less regular will make the game less predictable. And we can also work with the speed of the ball.

Let's consider the perfect bouncing we are using now to be 1. If the bouncing could take a value between 0.5 and 1.5, the bouncing would be less regular, but still keep a degree of realism:

  1. In order to use random values in Flutter and Dart, we need to import the math library. In the pong.dart file, add the import statement as shown here:
import 'dart:math';
  1. Then, in the _PongState class, let's write a method, called randomNumber(), which returns a random double number...