Tutorial 12: Further Learning

Resources for Further Learning

Official Documentation

The Flutter team provides comprehensive documentation covering every aspect of Flutter development, from getting started to advanced topics.

  • Flutter Docs: The official Flutter documentation is the go-to resource for understanding the fundamentals, widgets, state management, and more. It’s regularly updated to reflect the latest features and best practices.
  • API Reference: The Flutter API reference offers detailed information on Flutter’s extensive set of libraries and classes.
  • Flutter YouTube Channel: The Flutter YouTube channel features tutorials, development tips, and updates on new features.

Community Resources

The Flutter community is vibrant and supportive, offering knowledge through various platforms.

Courses and Tutorials

Many online platforms offer structured learning paths ranging from beginner to advanced levels.

  • Udemy: Platforms like Udemy offer comprehensive Flutter courses that cover everything from the basics to building full-fledged apps, often with a focus on hands-on learning.
  • Codecademy & Pluralsight: These platforms provide Flutter courses that blend interactive coding exercises with instructional content.
  • Codelabs & Workshops: Flutter’s official codelabs provide guided, tutorial-style content that walks you through the process of building apps and adding features with Flutter.

Flutter Events and Meetups

Attending Flutter events, conferences, and meetups virtually or in person can be a great way to connect with the community, learn from experts, and stay updated on the latest developments.

Encouragement to Practice

Building Personal Projects

1. Start Small

Begin with simple projects that reinforce fundamental concepts. Small apps that solve specific problems allow you to experiment with Flutter’s features without becoming overwhelmed.

2. Increment Complexity

Gradually increase the complexity of your projects. Try integrating external APIs, adding more complex state management solutions, or exploring custom animations and interactions.

3. Portfolio Development

Use personal projects to build a portfolio. A well-documented portfolio showcasing a range of projects can be invaluable for career opportunities and personal growth.

Contributing to Open Source

1. Explore Flutter Projects

Look for open-source Flutter projects on platforms like GitHub. Many projects welcome contributions of all sizes, from bug fixes to new features.

2. Start with Issues

Begin by addressing open issues, especially those tagged as “good first issue” or “help wanted.” This can help you get familiar with the project’s codebase and contribution process.

3. Create Pull Requests

Once you’ve made changes or added features, submit a pull request. Be sure to follow the project’s contribution guidelines and be open to feedback from project maintainers.

4. Open Source Your Work

Consider making your own projects open source. This invites collaboration and feedback and can significantly impact your learning journey.

Networking with Other Developers

1. Join Flutter Communities

Participate in Flutter forums, social media groups, and local meetups. Platforms like Reddit, Discord, and LinkedIn host vibrant communities where developers share resources, discuss challenges and offer support.

2. Attend Conferences and Workshops

Flutter events, conferences, and workshops are great opportunities to learn from experienced developers, discover the latest trends, and connect with the community.

3. Collaborate on Projects

Team up with other developers on projects. Collaboration can introduce new perspectives, coding styles, and problem-solving techniques.

4. Share Your Knowledge

Whether through blog posts, tutorials, or talks at local meetups, sharing your experiences and insights can help others while reinforcing your own understanding.

Final Thoughts

Practical experience is invaluable in the tech world. By building personal projects, contributing to open source, and engaging with the Flutter community, you improve your skills and contribute to the ecosystem.

These activities foster a cycle of learning, building, and sharing that propels both personal growth and the advancement of the technology itself. Embrace the journey, enjoy the process, and actively participate in the Flutter community.

Tutorial 11: Advanced Features

Advanced UI Components and Techniques

Custom Widgets and Reusability

Creating custom widgets helps encapsulate and abstract complex UI parts and promotes reusability across your app.

  • Creating Custom Widgets: Identify common UI elements in your app and abstract them into custom widgets. This could be anything from a customized button to a complex layout pattern you use frequently.
  • Parameterization: Make your custom widgets flexible by adding parameters. This allows for customization and reuse in different contexts within your app.


class CustomButton extends StatelessWidget {
  final String label;
  final VoidCallback onPressed;

  const CustomButton({Key key, this.label, this.onPressed}) : super(key: key);

  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: onPressed,
      child: Text(label),

Responsive and Adaptive Design

Ensuring your app looks great on any device and platform is important for a broad appeal.

    • MediaQuery: Use MediaQuery to get the size of the current screen and adjust your layout accordingly.
    • LayoutBuilder:It allows widgets to adapt to the parent widget’s constraints, making it easier to create responsive designs.
    • Adaptive Widgets: Flutter offers several widgets that automatically adapt their appearance based on the platform (iOS or Android), such as Switch.adaptive.


Widget build(BuildContext context) {
  var size = MediaQuery.of(context).size;

  return Container(
    padding: size.width > 600 ? EdgeInsets.all(50) : EdgeInsets.all(10),
    child: Text(‘Responsive Text’),

Advanced Animation Techniques

Animations can significantly enhance the user experience when used appropriately.

  • AnimationController: It manages the animation, allowing for fine-grained control over the timing and progression.
  • CustomTween: Create custom tween classes for animating different properties or complex custom objects.
  • Physics-based Animations: Use the physics package for animations that mimic real-world behavior.


AnimationController _controller = AnimationController(
  duration: const Duration(seconds: 2),
  vsync: this,

void initState() {

void dispose() {

// Use the _controller for animation in your widget build method

Flutter's Rendering Engine

Understanding the Rendering Pipeline

Flutter’s rendering engine is designed to handle the UI’s layout and painting efficiently, ensuring optimal performance even for complex and dynamic interfaces.

Here’s an overview of the rendering pipeline:

    • Widgets: Everything in Flutter starts with widgets, the basic building blocks of your app’s UI. Widgets are descriptions of what the UI should look like based on the current app state.
    • Element Tree: When a widget is used (instantiated), it gets an associated element in the element tree. Elements are the instantiation of a widget at a particular location in the tree and track the lifecycle of their widget.
    • Render Objects: Each element in the tree corresponds to a render object, which determines the widget’s layout (size, position) and handles painting. Render objects communicate with the underlying rendering engine, written in C++, to draw themselves onto the screen.
    • Layers: To optimize painting, Flutter uses a system of layers that can be reused across frames if the underlying scene doesn’t change. This significantly reduces the computational load for animations and transitions.
    • Painting: Finally, the render objects paint themselves onto the screen according to the layout previously computed. Flutter’s rendering engine utilizes Skia, a high-performance 2D graphics library, to draw widgets.

Custom Painting and Effects

For situations where predefined widgets don’t meet your needs, Flutter allows for custom painting and the creation of unique effects.

CustomPaint Widget

The CustomPaint widget provides a canvas on which you can draw custom shapes, lines, and other graphical elements. You define a custom painter by extending the CustomPainter class and implementing the paint and shouldRepaint methods.

class MyCustomPainter extends CustomPainter {
  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..color = Colors.blue
      ..strokeWidth = 5;

    canvas.drawCircle(Offset(size.width / 2, size.height / 2), 50, paint);

  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;

Implementing Custom Effects

Beyond simple shapes, you can use the Canvas API to implement complex graphical effects, such as gradients, paths, and shadows. The flexibility of the CustomPaint widget combined with the powerful Skia graphics library enables the creation of sophisticated visual effects and custom UI components.

void paint(Canvas canvas, Size size) {
  final Path path = Path()
    ..moveTo(0, size.height / 2)
    ..lineTo(size.width, size.height / 2);
  final Paint paint = Paint()
    ..color = Colors.teal
    ..style = PaintingStyle.stroke
    ..strokeWidth = 4.0
    ..shader = LinearGradient(
      colors: [Colors.red, Colors.blue],
    ).createShader(Rect.fromLTWH(0, 0, size.width, size.height));

  canvas.drawPath(path, paint);

Integrating with Hardware and External Services

Accessing Device Sensors

Many apps rely on data from device sensors to provide features like location tracking, motion detection, or orientation changes. Flutter supports these integrations through various packages available on pub.dev.

1. Using the location Package for GPS Data:

To access the device’s GPS sensor for location data:

  • Add the location package to your yaml file.
  • Request permission to use the device’s location services.
  • Use the package’s API to get the current location or subscribe to location changes.

import ‘package:location/location.dart’;

Location location = new Location();

bool _serviceEnabled;
PermissionStatus _permissionGranted;
LocationData _locationData;

_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
  _serviceEnabled = await location.requestService();
  if (!_serviceEnabled) {

_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
  _permissionGranted = await location.requestPermission();
  if (_permissionGranted != PermissionStatus.granted) {

_locationData = await location.getLocation();

2. Using the sensors Package for Accelerometer and Gyroscope Data:

The sensors package provides access to accelerometer and gyroscope sensors, allowing apps to detect motion and orientation.

    • Include the sensors package in your app dependencies.
    • Subscribe to sensor data streams to receive updates.

import ‘package:sensors/sensors.dart’;

accelerometerEvents.listen((AccelerometerEvent event) {
  // Do something with the event.
gyroscopeEvents.listen((GyroscopeEvent event) {
  // Do something with the event.

Using Background Services

Running tasks in the background allows your app to perform actions even when it’s inactive, such as downloading content, playing audio, or fetching data regularly.

1. Using the workmanager Package:

The workmanager package is a convenient way to schedule background tasks. It provides a simple API to run tasks once, periodically, or when certain conditions are met, like network availability.

    • Add workmanager to your yaml.
    • Initialize the WorkManager and define tasks.

import ‘package:workmanager/workmanager.dart’;

void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) {
    // Perform your task and return true if successful
    return Future.value(true);

void main() {
    callbackDispatcher, // The top-level function, see above
    isInDebugMode: true,
    frequency: Duration(minutes: 15),

Advanced State Management and Architecture

Exploring Advanced Patterns

Bloc and Cubit

The Bloc pattern separates presentation from business logic, using streams to manage state changes. It’s highly recommended for complex apps with multiple data sources or those requiring detailed state management across various screens.

    • Bloc: Utilizes events to trigger state changes. Each event processed by a Bloc yields a new state, ensuring a unidirectional data flow.
    • Cubit: A simpler version of Bloc, which allows state changes through direct function calls without the need for events.

Implementing Bloc or Cubit involves creating a separate layer for business logic, which reacts to user inputs (events) and outputs states that the UI listens to and rebuilds from.

Provider and Riverpod

While Provider offers a straightforward way to manage state and access objects, Riverpod extends Provider’s capabilities, offering more flexibility and resolving some of its limitations.

    • Provider: Ideal for medium-sized apps, Provider simplifies state management and is easily combined with other patterns for more complex scenarios.
    • Riverpod: It introduces a globally accessible, compile-time safe approach, making it easier to manage state in larger applications with more complex needs.

Architectural Best Practices

Clear Separation of Concerns

Divide your app into layers (UI, logic, and data), ensuring each has distinct responsibilities. This separation simplifies maintenance and testing by isolating changes to specific app parts.


Break down your app into modules or packages based on features or functionality. This approach enhances code reusability, simplifies testing, and accelerates development by allowing parallel work on different features.

Immutable State

Favor immutable objects for your states. Immutability ensures that states are predictable and changes are explicit, reducing side effects and making your app easier to debug.

Reactive Programming

Embrace reactive programming principles, especially when dealing with complex state management and data flows. Libraries like RxDart can enhance your Bloc or Cubit implementations by providing advanced stream manipulation capabilities.


Invest in testing from the start, including unit, widget, and integration tests. A solid testing foundation ensures that your architecture supports easy testing, leading to more reliable code.

Performance Considerations

Design your architecture with performance in mind. Efficient state management, use of resources, and avoiding unnecessary rebuilds can significantly impact your app’s responsiveness and fluidity.

Performance Optimization

Benchmarking and Optimization Techniques

1. Profiling Tools

Use Flutter’s built-in profiling tools, available in Flutter DevTools, to analyze your app’s performance. These tools provide insights into CPU usage, frame rendering times, and memory consumption. Profiling helps identify parts of your app that are causing slowdowns or using excessive resources.

2. Tracing Performance Issues

Flutter DevTools’ timeline view allows you to trace the execution of your app frame by frame. Look for frames that exceed the 16ms mark needed to achieve a smooth 60 frames per second (fps) experience. Identifying long frames can help you pinpoint specific widgets or functions that need optimization.

3. Using the Widget Inspector

The Widget Inspector within Flutter DevTools can help identify unnecessary widget rebuilds. Minimizing rebuilds, especially for complex widget trees, can significantly improve performance.

4. Benchmark Tests

Write benchmark tests for critical parts of your app, such as database access or complex computations. Flutter’s benchmark package can assist in automating these tests, allowing you to measure the impact of changes and optimizations over time.

Building Highly Performant Apps

1. Efficient State Management

Choose a state management approach that minimizes unnecessary updates to the UI. Techniques like memoization and selectively rebuilding widgets can reduce workload and improve responsiveness.

2. Optimizing Render Cycles

Avoid deep widget trees where possible, as they can increase the workload for rendering and layout calculations. Use the const keyword for widgets that do not change, and consider custom render objects for complex or highly reusable components.

3. Image and Asset Optimization

Large images and assets can significantly impact your app’s memory usage and performance. Use compressed image formats, ensure assets are appropriately sized for their use case, and leverage caching mechanisms to reduce load times.

4. Lazy Loading

Implement lazy loading for lists, grids, and other data collections. Widgets like ListView.builder only create items as needed, reducing initial load times and memory consumption.

5. Asynchronous Programming

Utilize Dart’s async/await features to perform IO-bound work, such as file access or network requests, without blocking the main thread. This ensures your app remains responsive to user input while performing background tasks.

6. Code Splitting and Modularization

Breaking your app into smaller, independent modules can help reduce initial load times and make it easier to manage code. For web and desktop platforms, consider splitting code to load only the necessary code for the current view or feature.

Cross-Platform Best Practices

Code Sharing Between Flutter and Web

1. Universal Widgets and Logic

Leverage Flutter’s widget system and Dart’s programming capabilities to share UI and business logic across platforms. Most Flutter widgets work seamlessly on both mobile and web, allowing for a high degree of code reuse.

2. Conditional Imports

Use Dart’s conditional import feature for platform-specific functionality. This allows you to specify different implementations for your code depending on the target platform while keeping your application logic unified.

import ‘interface_default.dart’
  if (dart.library.html) ‘interface_web.dart’
  if (dart.library.io) ‘interface_mobile.dart’;

void main() {

3. Feature Parity

Aim for feature parity across platforms whenever feasible. While certain capabilities may differ between mobile and web (e.g., offline storage, background processes), providing a consistent feature set enhances the user experience.

Platform-Specific Code and UI

1. Adapting UI for Platforms

While Flutter allows for a high degree of UI consistency, some adjustments may be necessary to match platform conventions (e.g., navigation patterns and visual design). Use Flutter’s platform-specific widgets, like Cupertino for iOS and Material for Android, or adjust layouts and controls based on the platform to provide a native look and feel.

2. Handling Platform-Specific APIs

When accessing platform-specific APIs (e.g., sensors, storage, permissions), you may need to use platform channels in Flutter to communicate with native code. This is particularly relevant for features not directly supported by Flutter or third-party packages.

3. Responsive Design

Make sure your UI is responsive and adapts to different screen sizes and orientations. This is crucial for web apps that can be accessed on various devices, from smartphones to desktops. Utilize MediaQuery, Flexible, Expanded, and responsive layout builders to create a UI that scales gracefully.

4. Testing on Multiple Platforms

Regularly test your app on all target platforms to catch platform-specific issues early. This includes testing on various browsers for web apps and iOS and Android devices for mobile apps.

5. Performance Considerations

Be mindful of performance differences across platforms. For example, web apps may have different performance characteristics due to browser execution environments. Optimize assets, minimize resource usage, and leverage caching to ensure smooth performance.

Advanced Packages and Plugins

Utilizing Third-Party Libraries

1. Discovering Packages

The primary resource for finding Flutter packages is pub.dev, the official package repository. It hosts various packages for various functionalities, from network requests and state management to animations and device hardware integration.

2. Evaluating Packages

Before integrating a third-party package, evaluate its quality, maintenance status, and community support.

Check for:

    • The package version and update frequency.
    • Open and closed issues on the package’s GitHub repository.
    • Documentation and example usage.
    • Compatibility with your target Flutter version and platforms.

3. Integrating a Package

To add a package to your project:

    • Add the package dependency to your yaml file.
    • Run flutter pub get to install the package.
    • Import the package in your Dart code and use it according to the documentation.

Developing Custom Plugins

When existing third-party packages don’t meet your requirements, or you need to access platform-specific APIs not covered by Flutter, developing a custom plugin is the solution.

1. Plugin Structure

A Flutter plugin project contains Dart code for the Flutter interface, along with native code for iOS (Swift or Objective-C) and Android (Kotlin or Java). This structure allows you to implement platform-specific functionalities while providing a unified Dart API for Flutter apps.

2. Creating a Plugin

Use the Flutter CLI to create a plugin project template:

flutter create –template=plugin my_plugin

This command generates a plugin project with the necessary structure for adding Dart and native code.

3. Implementing Native Code

Within the plugin project, navigate to the iOS and Android directories to add your platform-specific code. Use platform channels to communicate between Dart and native code layers.

4. Publishing a Plugin

Once your plugin is tested and documented, you can publish it to pub.dev to share with the Flutter community. Use the flutter pub publish command, ensuring you’ve followed the package publishing guidelines outlined in the Flutter documentation.

5. Maintaining Your Plugin

Keep your plugin updated with the latest Flutter releases and address issues users report. Active maintenance is crucial for the long-term success of your plugin.

Tutorial 9: Testing and Debugging

Writing Unit and Widget Tests

Introduction to Testing in Flutter

Flutter provides a comprehensive framework for automated testing, allowing you to test your app at the unit, widget, and integration levels. Testing ensures your code performs as expected and helps prevent regressions.

Writing Unit Tests

Unit tests verify the behavior of a single function, method, or class. In Flutter, the test package is used to write unit tests.

  • Add the test dependency: Ensure your yaml includes the test package under dev_dependencies.

    sdk: flutter
  test: ^1.16.0

  • Create a test file: Tests are typically written in a file within the test directory of your Flutter project.
  • Write a unit test: Use the test() function to define a test case and the expect() function to assert the expected outcomes.

Example unit test for a simple function:

import ‘package:test/test.dart’;

int add(int a, int b) => a + b;

void main() {
  test(‘adds two numbers’, () {
    final result = add(1, 2);
    expect(result, 3);

Writing Widget Tests

Widget tests (or component tests) verify the behavior of Flutter widgets in isolation.

  • Use the flutter_test package: This package, part of the Flutter SDK, provides tools for widget testing.
  • Write a widget test: Create a test that builds the widget and verifies its contents or behavior.

Example widget test for a simple MyWidget:

import ‘package:flutter/material.dart’;
import ‘package:flutter_test/flutter_test.dart’;

void main() {
  testWidgets(‘MyWidget has a title and message’, (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(home: MyWidget(title: ‘T’, message: ‘M’)));

    expect(find.text(‘T’), findsOneWidget);
    expect(find.text(‘M’), findsOneWidget);

H3Debugging Apps

Flutter provides various tools and techniques for debugging and optimizing app performance. Understanding how to use these tools effectively can save you time and make your apps more reliable for users.

1. Tools for Debugging

Flutter DevTools

A powerful suite of debugging tools that run in a browser. DevTools offers a wide range of features for inspecting the UI layout and structure, diagnosing performance issues, and viewing general log and diagnostics information. Key features include the widget inspector, timeline view for performance analysis, and memory and network profilers.

How to Use

Run your app in debug mode, then execute flutter devtools in your terminal and open the provided URL in your browser.

IDE Integration

Both Android Studio (IntelliJ) and Visual Studio Code offer integrated debugging experiences for Flutter apps. These IDEs allow you to set breakpoints, step through code, inspect variables, and evaluate expressions on the fly.

  • Breakpoints: Set breakpoints in your code where you want execution to pause. This allows you to inspect the current state, including variables and the call stack.
  • Step Over/Into: Navigate through your code line by line to understand the flow of execution and locate the source of bugs.

2. Common Debugging Techniques

Print Debugging

Sometimes, the simplest techniques are the most effective. Strategically placing print statements in your code can help track down the execution flow or the state of variables at specific points.

print(‘Current value of variable: $variableName’);

Hot Reload and Hot Restart

Flutter’s hot reload feature lets you quickly test changes without restarting your app, making it easier to iterate on bug fixes. Use a hot restart to reset the app’s state and reload everything from scratch when necessary.

Using Assertions

Dart’s assert statement is a handy tool for catching errors during development. Assertions can validate assumptions in your code, catching errors that might otherwise go unnoticed. Assertions are only active in debug mode and do not impact your release build.

3. Performance Profiling

Identifying and fixing performance issues is important for maintaining a smooth user experience. Flutter DevTools’ performance view provides detailed insights into your app’s performance characteristics.

Frame Rendering Times

The performance view in DevTools displays a timeline of your app’s frame rendering times. Frames that take too long to render (over 16ms for 60fps) are highlighted, helping you identify performance issues related to UI rendering.

Widget Rebuild Profiling

Excessive or unnecessary widget rebuilds can degrade your app’s performance. Use the Flutter inspector’s performance overlay to identify widgets that are being rebuilt frequently. Optimize these parts of your app to minimize rebuilds.

Memory Profiling

Flutter DevTools also includes a memory profiler that helps you track memory usage over time, identify memory leaks, and analyze memory allocations. Monitoring memory usage is essential for preventing crashes and ensuring your app runs smoothly across all devices.

Tutorial 10: Deployment

Preparing for Release

Optimizing Performance

Before releasing your app, optimizing its performance is important to ensure a smooth user experience.

Consider the following:

  • Minimize Animation Jank: Make sure animations run at 60fps by profiling and optimizing performance using Flutter DevTools.
  • Reduce App Size: Use the flutter build apk –split-per-abi (for Android) or flutter build ios –release (for iOS) commands to build your app, which helps reduce its size.
  • Optimize Images: Compress images and use the appropriate resolutions to minimize the impact on app size and performance.

Building for iOS and Android


  • Generate an App Bundle or APK: Use flutter build appbundle to generate an App Bundle for the Google Play Store or flutter build apk for an APK.

Sign Your App: Ensure your app is signed with the correct key before uploading it to the Play Store


  • Archive and Upload: Open your iOS project in Xcode, select Product > Archive, and follow the prompts to upload your app to App Store Connect.
  • App Store Review: Make sure your app complies with the App Store Review Guidelines before submitting it for review.

Application Versioning

Proper versioning is essential for app maintenance and user clarity. Flutter uses a simple versioning system located in the pubspec.yaml file.

Version Format

The version is specified in a major.minor.patch+build format.

For example, version: 1.0.0+1.

    • Major: Indicates significant changes that may break compatibility.
    • Minor: Introduces new features in a backward-compatible manner.
    • Patch: Fixes bugs and makes minor improvements without adding new features.

Build: An optional number that indicates iterations

version: 1.0.0+1

When preparing for a new release, increment the appropriate version number(s) based on the changes made. This practice helps track different versions of your app and manage updates efficiently.

Publishing to App Stores

Google Play Store

1. Create a Google Play Developer Account

Sign up for a developer account on the Google Play Console. There’s a one-time fee associated with creating the account.

2. Prepare App Listing

Before uploading the app bundle or APK, prepare your app’s listing with screenshots, a detailed description, categorization, and other metadata.

3. Upload the App Bundle or APK

Use the Play Console to upload your app’s release bundle or APK. You’ll need to create a new app release in the console, where you can manage the app’s artifacts.

4. Set Content Rating and Pricing

Complete the content rating questionnaire and set up your app’s pricing and distribution details.

5. Review and Publish

Submit your app for review. Once approved, you can publish it immediately or schedule the launch.

Apple App Store

1. Enroll in the Apple Developer Program

Enrollment is required to publish apps on the App Store. There’s an annual membership fee.

2. Prepare Your App for Submission

Use Xcode to archive and prepare your app for submission. Ensure your app complies with Apple’s App Store Review Guidelines.

3. Create Your App Listing in App Store Connect

Similar to the Play Store, set up your app’s listing in App Store Connect with screenshots, descriptions, and other necessary information.

4. Upload Your App Using Xcode

Xcode integrates with App Store Connect, allowing you to upload your app directly from the IDE after archiving.

5. Submit for Review

Once your app is uploaded, submit it for review. You can monitor the status of your submission in App Store Connect.

6. Release Your App

After approval, you can choose to release your app immediately or schedule a release date.

Managing App Updates and Feedback

Releasing Updates

Both app stores allow you to release updates to your app. Use this opportunity to fix bugs, add new features, and improve performance. Ensure each update is accompanied by versioning and changelog details.

Monitoring Feedback

User reviews and ratings are valuable sources of feedback. Monitor these closely and consider user suggestions and complaints in future updates.


Engage with your users through the review section by responding to feedback. This can improve your app’s rating and user satisfaction.

Publishing your Flutter app on the Google Play Store and Apple App Store opens up your project to millions of potential users. The process requires careful planning and attention to detail but is a critical step in the app development lifecycle. Properly managing app updates and user feedback post-launch is equally important for sustaining your app’s success and growth.

Tutorial 8: Animations and Graphics, Advanced State Management Techniques

Animations and Graphics

Basics of Animations

Flutter’s animation system is based on Animation objects that interpolate over a specified duration from one value to another. The framework provides Tween for value interpolation, AnimationController for managing animation states and durations, and AnimatedWidget or AnimatedBuilder for linking the output of an animation to the UI.

    • AnimationController: Manages the animation’s state (e.g., start, stop) and duration.

AnimationController controller = AnimationController(
  duration: const Duration(seconds: 2),
  vsync: this,

  • Tween: Defines the range between the starting and ending values of the animation.

final Animation<double> animation = Tween<double>(begin: 0, end: 300).animate(controller);

  • Starting the Animation: Trigger the animation using the controller.


Custom Animations

Custom animations allow for more control and flexibility than pre-built animation widgets. By defining your own Tweens and utilizing the AnimationController, you can create unique animations that fit your app’s specific needs.

  • Creating a Custom Animation Widget: Use AnimatedBuilder or extend AnimatedWidget to create a widget that rebuilds whenever the animation’s value changes.

  animation: animation,
  builder: (context, child) {
    return Container(
      height: animation.value,
      width: animation.value,
      child: child,
  child: FlutterLogo(),

Integrating Graphics

In addition to animations, Flutter allows for the integration of custom graphics via the CustomPaint widget and drawing operations.

  • CustomPaint: It provides a canvas to draw custom shapes, lines, and other graphics.
  • CustomPainter: It implements this class to define your custom drawing code.

class MyCustomPainter extends CustomPainter {
  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..color = Colors.blue
      ..strokeWidth = 5;

    canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), paint);

  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;

Use CustomPaint in your widget tree and pass it your CustomPainter to render your custom graphics.

  size: Size(200, 200),
  painter: MyCustomPainter(),

State Management Deep Dive

Comparison of Techniques

1. Provider

It is recommended by the Flutter for its simplicity and effectiveness. It uses a consumer-provider model, making managing and accessing data across the widget tree easy.

  • Advantages: Easy to implement and understand. It integrates well with Flutter’s reactive model.
  • Disadvantages: It might become cumbersome for very complex app states or when managing many distinct pieces of state.

2. Bloc (Business Logic Component)

Bloc separates the business logic from the UI, managing the state through streams and sinks. Ideal for more complex applications requiring advanced state management.

  • Advantages: Clean separation of concerns, making the code more maintainable and testable. Scales well for large applications.
  • Disadvantages: Steeper learning curve and more boilerplate code compared to simpler state management solutions.

3. Riverpod

An evolution of Provider, offering more flexibility and resolving some of Provider’s limitations. It’s compile-safe, meaning most errors are caught at compile time.

  • Advantages: Compile-time safety, flexibility in accessing and providing state, and works outside the widget tree.
  • Disadvantages: It can take time to grasp initially, especially for beginners.

4. Redux

A predictable state container that manages the app’s state in a single immutable state object. Actions are dispatched to modify this state, and reducers define how actions transform the state.

  • Advantages: Centralized state management makes debugging and testing easier. The unidirectional data flow is clear and predictable.
  • Disadvantages: It might be overkill for small to medium-sized apps and requires understanding Redux principles.

Implementing Complex State

Managing a complex state involves dealing with multiple interdependent or independent pieces of state that drive the UI.

Here are some strategies:

  • Modularization: Break down the app state into smaller, manageable parts. Each part can be managed by its own state management solution (e.g., a Bloc for complex logic, Provider for UI-related state).
  • State Normalization: Similar to database normalization, this involves storing state in a structured format that minimizes redundancy and dependency.

Performance Considerations

State management can significantly impact the performance of your Flutter app.

Here are key considerations:

  • Minimize Rebuilds: Use tools like const widgets, Builder widgets, or conditionally rebuilding parts of the widget tree to prevent unnecessary rebuilds.
  • Lazy Loading: For large datasets or complex states, consider loading data lazily or incrementally to avoid performance bottlenecks.
  • Monitor Performance: Use Flutter’s performance profiling tools to monitor the app’s performance and identify bottlenecks related to state management.

Tutorial 7: Understanding Forms, Input Handling, and Validation

Forms, Input Handling, and Validation

Creating Forms

Flutter provides a Form widget that acts as a container for TextFormField widgets, making it easy to group and manage multiple form fields.

  • Using the Form Widget: Wrap your input fields within a Form widget. Assign a unique GlobalKey<FormState> to the form to manage its state.

final _formKey = GlobalKey<FormState>();

Widget build(BuildContext context) {
  return Form(
    key: _formKey,
    child: Column(
      children: <Widget>[
          decoration: InputDecoration(labelText: ‘Enter your username’),
        // Add more TextFormFields here

Handling User Input

TextFormField widgets automatically manage the input state. However, you should capture the input when submitting a form.

  • Capturing Input: Use the onSaved property of TextFormField to save input value to a variable when the form is saved.

  decoration: InputDecoration(labelText: ‘Enter your username’),
  onSaved: (value) {
    // Save the input value to a variable
    username = value;

Validating Input

Validation ensures the user correctly enters the required information before processing the form.

  • Using Validators: The validator property of TextFormField allows you to provide validation logic that is automatically invoked when the form is saved.

  decoration: InputDecoration(labelText: ‘Enter your email’),
  validator: (value) {
    if (value.isEmpty || !value.contains(‘@’)) {
      return ‘Please enter a valid email.’;
    return null; // Return null if the input is valid

  • Triggering Validation: Use the validate() method to trigger the validation of all the TextFormField widgets in the form.

  onPressed: () {
    if (_formKey.currentState.validate()) {
      // If the form is valid, display a Snackbar or save form data
  child: Text(‘Submit’),

Local Persistence

Storing data locally on the device allows your app to cache data, save preferences, and more. Flutter supports various methods for local persistence, including shared preferences, file system access, and SQLite databases.

Shared Preferences

Shared Preferences is a key-value store for lightweight data. It’s perfect for storing simple data, such as user settings.

  • Adding the Shared Preferences Package: Include the shared_preferences package in your yaml file and run flutter pub get.
  • Using Shared Preferences:
    • Import the package and use it to read and write preferences.

import ‘package:shared_preferences/shared_preferences.dart’;

Future<void> savePreference(String key, String value) async {
  final SharedPreferences prefs = await SharedPreferences.getInstance();
  prefs.setString(key, value);

Future<String> getPreference(String key) async {
  final SharedPreferences prefs = await SharedPreferences.getInstance();
  return prefs.getString(key) ?? ”;

File System Access

You can read and write files directly to the device’s file system for more complex data storage needs.

import ‘package:path_provider/path_provider.dart’;
import ‘dart:io’;

Future<String> get _localPath async {
  final directory = await getApplicationDocumentsDirectory();
  return directory.path;

Future<File> get _localFile async {
  final path = await _localPath;
  return File(‘$path/data.txt’);

Future<File> writeFile(String data) async {
  final file = await _localFile;
  return file.writeAsString(data);

Future<String> readFile() async {
  try {
    final file = await _localFile;
    return await file.readAsString();
  } catch (e) {
    return ”;


SQLite provides a robust solution for structured data storage. With the sqflite package, Flutter apps can create, query, update, and delete data within a local SQLite database.

Setting Up sqflite

1. Add sqflite to your pubspec.yaml:

 sqflite: latest_version
 path_provider: latest_version

Replace latest_versionwith the current version numbers of sqflite and path_provider.

2. Import sqflite and path_provider:

import ‘package:sqflite/sqflite.dart’;
import ‘package:path/path.dart’;
import ‘package:path_provider/path_provider.dart’;

3. Open Database:

Create a function to open the database, creating it if it doesn’t exist, and define its schema.

Future<Database> openDatabase() async {
  final directory = await getApplicationDocumentsDirectory();
  final path = join(directory.path, ‘my_database.db’);
  return await openDatabase(path, version: 1, onCreate: (db, version) async {
    await db.execute(”’
      CREATE TABLE my_table(
        name TEXT

CRUD Operations:

1. Create (Insert):

Future<void> insertData(Database db, Map<String, dynamic> data) async {
 await db.insert(‘my_table’, data);

2. Read (Query):

Future<List<Map<String, dynamic>>> queryData(Database db) async {
 return await db.query(‘my_table’);

3. Update:

Future<void> updateData(Database db, Map<String, dynamic> data) async {
 await db.update(‘my_table’, data, where: ‘id = ?’, whereArgs: [data[‘id’]]);

4. Delete:

Future<void> deleteData(Database db, int id) async {
 await db.delete(‘my_table’, where: ‘id = ?’, whereArgs: [id]);

This setup guides you through adding SQLite to your Flutter project, opening a database, and performing basic CRUD operations, mirroring the straightforward examples given for shared preferences and file system access.

Tutorial 6: Working with External Flutter Packages and APIs

Adding External Packages

Incorporating external packages into your Flutter project is a straightforward process, managed through the pubspec.yaml file located at the root of your project directory.

Using pubspec.yaml

1. Find a Package: Visit dev, the official package repository for Dart and Flutter, to find a package that suits your needs. Use the search function or browse categories to find a package.

2. Edit pubspec.yaml: Open your yaml file in your editor. Under the dependencies section, add the package name and version you wish to include in your project. The version can be specified or left blank to use the latest version automatically.

    sdk: flutter
  http: ^0.13.3

3. Install the Package: Save your yaml file and run flutter pub get in your terminal or command prompt. This command downloads the package and makes it available in your project.

Popular Packages for Flutter

Several packages have become key components in Flutter development due to their utility, ease of use, and functionality.

Here are a few examples:

Example: Using the http Package

After adding the http package to your pubspec.yaml, you can use it in your app to make HTTP requests, such as fetching data from an API.

import ‘package:flutter/material.dart’;
import ‘package:http/http.dart’ as http;
import ‘dart:convert’;

class MyApp extends StatelessWidget {
  Future<void> fetchData() async {
    final response =
        await http.get(Uri.parse(‘https://jsonplaceholder.typicode.com/posts/1’));
    if (response.statusCode == 200) {
      // If server returns an OK response, parse the JSON.
    } else {
      // If the server did not return a 200 OK response,
      // throw an exception.
      throw Exception(‘Failed to load post’);

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: fetchData,
            child: Text(‘Fetch Data’),

This example demonstrates how to use the http package to perform a simple GET request and print the response. Utilizing external packages like http significantly reduces the amount of boilerplate code you need to write, allowing you to focus on building the core features of your app.

Networking in Flutter

Fetching Data from the Web

To fetch data from the web, you can use the http package, which simplifies making HTTP requests.

  1. Add the http Package: First, ensure you’ve added the http package to your yaml file as described in the previous section and run flutter pub get.
  2. Making an HTTP Request:
      • Import the package in your Dart file.
      • Use the get method to make a GET request to the desired URL.


import ‘package:http/http.dart’ as http;

Future<http.Response> fetchData() {
 return http.get(Uri.parse(‘https://jsonplaceholder.typicode.com/posts/1’));

JSON Parsing

Receiving data from the web involves dealing with JSON (JavaScript Object Notation), a lightweight data-interchange format. Dart makes it easy to parse JSON with the built-in json library.

  1. Decode JSON Data:


import ‘dart:convert’;

Future<void> fetchAndParseData() async {
  final response =
      await http.get(Uri.parse(‘https://jsonplaceholder.typicode.com/posts/1’));
  if (response.statusCode == 200) {
    final Map<String, dynamic> data = jsonDecode(response.body);
  } else {
    throw Exception(‘Failed to load data’);

Displaying Fetched Data

After fetching and parsing the data, the next step is to display it within your app’s UI.

1. Use a Stateful Widget for Dynamic Content:

    • Convert your widget to a StatefulWidget if necessary to update the state when the data is received.

2. Fetching Data on Initialization:

3. Display the Data:

    • Use the fetched data to build your widgets dynamically. For example, display the data in a ListView or use it to populate Text widgets.


class MyDataWidget extends StatefulWidget {
  _MyDataWidgetState createState() => _MyDataWidgetState();

class _MyDataWidgetState extends State<MyDataWidget> {
  Map<String, dynamic> _postData;

  void initState() {
    fetchAndParseData().then((data) {
      setState(() {
        _postData = data;

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(‘Networking in Flutter’),
      body: Center(
        child: _postData == null
            ? CircularProgressIndicator()
            : Text(‘Title: ${_postData[‘title’]}’),

In this example, the app fetches data when it starts, parses the JSON response, and displays the title from the data in a Text widget. A CircularProgressIndicator is shown while the data is being fetched.

Tutorial 4: Create A Simple App for Flutter

Setting Up Your Flutter Environment

Installing Flutter SDK

1. Download the Flutter SDK:

  • Visit the official Flutter website to download the Flutter SDK. Choose the package corresponding to your operating system: Windows, macOS, or Linux.

2. Extract the SDK:

  • Windows: Extract the zip file to a desired location (e.g., C:\src\flutter). Avoid placing it in directories that require elevated permissions.
  • macOS/Linux: Extract the zip file to a location like ~/development/flutter. You can use the terminal with commands like unzip and mv to move the folder.

3. Update Your Path:

  • Ensure the flutter/bin directory is added to your PATH environment variable. This step is important for accessing Flutter commands globally from your terminal or command prompt.
  • Windows: Use the System Properties -> Environment Variables dialog to edit the PATH.
  • macOS/Linux: Add a line to your .bash_profile, .zshrc, or equivalent file, such as export PATH=”$PATH:pwd/flutter/bin”.

Verifying Installation with flutter doctor

Once the Flutter SDK is installed and the PATH is correctly set, use the flutter doctor command to verify your environment is set up correctly and identify any missing dependencies.

1. Open a Terminal or Command Prompt: Navigate to any directory.

2. Run flutter doctor: Type the command flutter doctor and press enter. The tool checks your environment and displays a report in the terminal window.

3. Review the Output: The flutter doctor’s output shows your Flutter installation’s status. It checks for installed tooling, the presence of necessary SDKs, and the configuration of your development environment.

  • A checkmark (✓) indicates a successfully verified item.
  • An exclamation mark (!) indicates a potential issue or a recommendation.
  • A cross (✗) signifies a missing dependency or an error that needs to be addressed.

4. Resolve Any Issues: Follow the instructions provided by the flutter doctor to resolve any detected problems. Common issues might involve accepting SDK licenses, installing missing tooling, or configuring your IDE.

Creating a New Flutter Project

After setting up your Flutter development environment, the next step in creating a simple app is to initiate a new Flutter project. This process involves using the command line to create the project and understanding the basic structure of a Flutter project.

Command Line Creation

1. Open Your Terminal or Command Prompt

  • For Windows, search for Command Prompt or PowerShell in your Start menu.
  • On macOS or Linux, open the Terminal application.

2. Navigate to Your Preferred Directory

Use the cd command to change directories to where you want to create your new Flutter project.

For example:

cd Documents/FlutterProjects

3. Create the Project

Run the flutter create command followed by the name of your project. Project names should be all lowercase, with underscores to separate words as per Dart package naming conventions.

For example:

flutter create my_simple_app

This command creates a new Flutter project with the specified name in the current directory, including all necessary Dart and Flutter files.

Project Structure Overview

After creating your project, you’ll see the following key directories and files within your project folder:

  • android/ and ios/: These directories contain files necessary to build your app on Android and iOS platforms, respectively. They are generated by Flutter but can be modified for platform-specific functionalities.
  • lib/: This is where your Dart code lives. By default, it contains a single file, main.dart, which is the starting point of your Flutter app.
  • test/: Contains Dart files for testing your application. Flutter encourages Test-Driven Development (TDD) with unit tests, widget tests, and integration tests.
  • yaml: An important file that specifies your app’s dependencies (including Flutter itself), version, and other metadata. Here, you can add third-party packages, set up assets like images and fonts, and configure your app.
  • .dart_tool/, .idea/, .flutter-plugins, .flutter-plugins-dependencies, and .packages: These directories and files are automatically generated and manage the project’s dependencies and SDK references. They should not be manually altered.
  • md: A markdown file where you can provide information about your app, like how to install and use it.

Designing the App's UI

After creating your Flutter project, the next step is to design your app’s user interface (UI). Flutter makes this process intuitive and flexible with its widget-centric architecture.

Scaffold and AppBar

The Scaffold widget provides a high-level structure for implementing the basic visual layout of your app. It offers a framework to lay out various UI components, such as app bars, floating action buttons, and body content.

1. Using Scaffold

  • Open your dart file.
  • Inside the build method of your app’s main widget, return a MaterialApp
  • Set its home property to a new Scaffold widget to start structuring your app’s UI.

2. Adding an AppBar

  • Within the Scaffold, you can add an AppBar widget to the appBar The AppBar serves as the top bar of your app, typically displaying the app’s title or navigation controls.

Example code snippet

import ‘package:flutter/material.dart’;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(‘My Simple App’),
          backgroundColor: Colors.blueGrey,
        body: Center(
          // This is where your central widget will go

Adding a Central Widget

The body of your app can contain various widgets depending on what you want to display. Consider adding a text widget as the central element for a simple start.

1. Center Widget

  • Use the Center widget within the body of your Scaffold to center your content.

2. Text Widget

  • Inside the Center widget, add a Text widget to display a simple message.

Example addition to the previous snippet

body: Center(
  child: Text(‘Welcome to Flutter!’),

Customizing the Theme

Flutter allows you to easily customize the theme of your app, including colors, font styles, and more. This can be done by modifying the theme property of the MaterialApp widget.

1. Theme Customization

  • In the MaterialApp widget, set the theme property to a ThemeData instance where you can customize your app’s colors, typography, and other theme attributes.

Example Code

return MaterialApp(
  theme: ThemeData(
    primarySwatch: Colors.blueGrey,
    visualDensity: VisualDensity.adaptivePlatformDensity,
  home: Scaffold(
    appBar: AppBar(
      title: Text(‘My Simple App’),
    body: Center(
      child: Text(‘Welcome to Flutter!’),

Adding Interactivity

Introducing Stateful Widgets

Stateful widgets are dynamic; they can change state during the lifetime of the widget. When the widget’s state changes, the widget can be rebuilt with new data, allowing for interactive elements in your app.

1. Creating a Stateful Widget

  • Convert your main app widget into a stateful widget if it’s not already. This involves creating two classes: one for the widget itself and one for its state.

Example Code

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  // Widget state and build method

Implementing Buttons and Actions

Buttons are a fundamental element for user interaction. Let’s add a floating action button to our app and implement an action.

1. Adding a Floating Action Button

2. Implementing the Button Action

  • Define an action for the button, such as incrementing a counter, by updating a variable within your state class.

Example addition to the state class

int _counter = 0;

void _incrementCounter() {
  setState(() {

And in the Scaffold widget:

floatingActionButton: FloatingActionButton(
  onPressed: _incrementCounter,
  tooltip: ‘Increment’,
  child: Icon(Icons.add),

Updating Widget State

The setState method is important for updating the state of a stateful widget. It signals Flutter to redraw the widget with the updated state.

1. Displaying Updated State

  • Use the updated state variable to change what’s displayed in the UI. For example, display the updated _counter value in the Text

Example update to the build method

body: Center(
  child: Text(‘You have pressed the button $_counter times.’),

Navigating Between Screens

Creating Multiple Screens

In Flutter, each screen is typically represented by a widget. To demonstrate navigation, we’ll create two screens: a home screen and a details screen.

1. Home Screen

  • This is your main app screen. It might already exist as your MyApp widget’s home.

2. Details Screen

  • Create a new stateless widget representing the details page you want to navigate. For simplicity, let’s call it DetailsScreen.

Example DetailsScreen widget

  • Create a new stateless widget representing the details page you want to navigate. For simplicity, let’s call it DetailsScreen.

class DetailsScreen extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(‘Details Screen’),
      body: Center(
        child: Text(‘Welcome to the Details Screen!’),

Navigating with Routes

Flutter uses named routes to control navigation. This approach allows you to define all routes in one place and navigate using route names.

1. Define the Routes

  • In your MaterialApp widget, use the routes property to define all available routes. Assign a widget to each route that should be displayed when navigating to that route.

2. Navigate to the Details Screen

  • Use pushNamed(context, ‘/details’) to navigate to the DetailsScreen when a button is pressed or an action is taken.

Example of defining routes in MaterialApp

  // Initial route
  initialRoute: ‘/’,
  routes: {
    ‘/’: (context) => MyApp(),
    ‘/details’: (context) => DetailsScreen(),

Example of navigating to DetailsScreen from MyApp:

  onPressed: () {
    // Navigate to the details screen
    Navigator.pushNamed(context, ‘/details’);
  child: Text(‘Go to Details’),

3. Navigating Back

  • On the DetailsScreen, the user can navigate back to the previous screen using the back button in the AppBar or by using pop(context) if you need to trigger this action from a button or another widget.


Running Your App

After creating your Flutter app and setting up navigation between screens, the next step is to test and run your app. Flutter allows running apps on various devices, including emulators, simulators, and physical devices.

On an Emulator/Simulator

1. Setting Up an Emulator (Android) or Simulator (iOS)

  • Android Emulator:
    • Make sure you have Android Studio installed and the Android Emulator set up.
    • Open Android Studio, go to the AVD Manager and start one of your configured virtual devices.
  • iOS Simulator:
    • Ensure you have Xcode installed on your macOS.
    • Open Xcode and select Xcode > Open Developer Tool > Choose the desired device from the Simulator.

2. Running Your App

  • Open a terminal or command prompt.
  • Navigate to your project directory.
  • Run the command flutter run. Flutter automatically detects running emulators or simulators and launches the app on them.
  • If multiple devices are available, flutter run will prompt you to choose which device to use. Alternatively, you can specify a device with flutter run -d <device_id>.

On a Physical Device

1. Android Device

  • Enable “Developer options” and “USB debugging” on your Android device.
  • Connect your device to your development machine with a USB cable.
  • If prompted on your device, authorize your computer to access your device.
  • Run flutter run in your project directory. Flutter should detect your connected device and launch the app on it.

2. iOS Device

  • Open Xcode and navigate to Xcode > Preferences > Accounts. Add your Apple ID and create a development certificate.
  • Connect your iOS device to your macOS via USB.
  • Open the ios folder of your Flutter project with Xcode. Select the project in the left sidebar, then select your development team under Signing & Capabilities.
  • Trust your developer certificate on your iOS device by going to Settings > General > Device Management.
  • Run flutter run in your project directory. Flutter will detect your iOS device and launch the app on it.


  • For both Android and iOS physical devices, select the correct device using flutter devices to find the device ID and flutter run -d <device_id> to specify which device to run on if automatic detection does not work.
  • Ensure that your development machine and mobile device have proper drivers installed and are authorized for debugging.

Debugging and Troubleshooting

Common Issues and Solutions

1. App Does Not Compile or Run

  • Solution: Verify your development environment is correctly set up by running flutter doctor in the terminal. Ensure all dependencies are installed, and no issues are reported. Check that your device or emulator is running and recognized by Flutter.

2. Hot Reload Not Working

  • Solution: Hot Reload may not work if your code has syntax errors. Ensure your code is error-free. Also, Hot Reload only updates changes in the existing state; it doesn’t perform full state resets or affect static fields. For significant changes, consider using Hot Restart.

3. Layout and Rendering Issues

  • Solution: Use the Flutter Inspector to examine widget trees and understand how UI elements are structured on the screen. Ensure widgets are correctly nested and check for any constraints causing layout issues.

Using the Flutter Inspector

The Flutter Inspector is a powerful tool integrated into IDEs like Android Studio and Visual Studio Code, designed to help you visualize and explore widget trees. It provides insights into the UI structure and layout, making it easier to debug layout issues.

1. Accessing the Flutter Inspector

  • Android Studio: Open the Flutter Inspector by selecting View > Tool Windows > Flutter Inspector.
  • Visual Studio Code: Install the Flutter extension, and you’ll find the Flutter Inspector in the Dart & Flutter side panel when running your app.

2. Features of the Flutter Inspector

  • Widget Tree: Displays the current widget hierarchy of your running app. This is useful for understanding the structure of your UI and identifying where to make changes.
  • Layout Explorer: This helps you visually understand the dimensions and constraints of your widgets, making it easier to debug layout issues.
  • Performance Overlay: Shows performance graphs for your app, helping identify and diagnose rendering and computational bottlenecks.

3. Using the Flutter Inspector

  • Run your app in debug mode.
  • Open the Flutter Inspector in your IDE.
  • Navigate through the widget tree to select specific widgets. The Inspector will highlight selected widgets on the device screen.
  • Use the Layout Explorer to adjust widget properties and see real-time app layout changes.
  • Monitor the Performance Overlay for any performance issues and adjust your code accordingly.

Tutorial 5: Building Blocks of Flutter


Flutter widgets are divided into several categories, each serving different aspects of UI construction, such as layout, presentation, and interaction.

Layout Widgets

Layout widgets are used to structure the visual aspect of your app. They control how other widgets are displayed on the screen, including their size, position, and arrangement.

  • Row and Column: These widgets allow you to arrange other widgets horizontally (Row) or vertically (Column). They are versatile and commonly used for most layout needs.
  • Stack: It allows for the overlapping of widgets. A Stack widget can layer widgets on top of each other, which is useful for creating effects like badges or floating buttons.
  • GridView: Perfect for creating grid layouts, similar to a table or a collection of elements arranged in rows and columns.
  • ListView: It is ideal for displaying a scrolling list of elements vertically or horizontally.

Text and Image Widgets

Displaying text and images is fundamental to most apps. Flutter provides widgets specifically designed for these purposes.


The Text widget displays a string of text with single or multiple styles. It’s highly customizable, allowing you to adjust the font, size, weight, and alignment.

  ‘Hello, Flutter!’,
  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),


The Image widget displays an image. Flutter supports a range of image sources, including network images, local assets, and more.


Container and Padding

The Container widget is a versatile decoration widget that can be used to style its child widget with colors, borders, margins, padding, and more. It’s useful for creating custom shapes, providing padding, or aligning content.


Padding is used to create space around the inside of a container. It’s useful for spacing out widgets from their parent or from each other.

  padding: EdgeInsets.all(8.0),
  color: Colors.blue,
  child: Text(‘Padded Text’),


Margins create space around the outside of a container. Use the margin property of the Container widget to set it.

  margin: EdgeInsets.all(8.0),
  color: Colors.red,
  child: Text(‘Text with Margin’),

Navigation and Routing

Basic Navigation

The simplest form of navigation involves pushing and popping routes on the navigation stack.

Pushing a New Screen

  MaterialPageRoute(builder: (context) => NewScreen()),

Popping a Screen


Routes and Navigator

For more advanced navigation scenarios, Flutter uses named routes, which can be defined in the MaterialApp widget.

Define the Routes

  initialRoute: ‘/’,
  routes: {
    ‘/’: (context) => HomeScreen(),
    ‘/details’: (context) => DetailsScreen(),

Navigate to a Named Route

Navigator.pushNamed(context, ‘/details’);

Passing Data Between Screens

When pushing a new screen, you can pass data directly to the constructor of the widget you’re navigating to.

    builder: (context) => DetailsScreen(data: ‘Some data’),

Passing Data with Named Routes

For named routes, you can pass arguments using the arguments parameter of Navigator.pushNamed.

  arguments: ‘Some data’,

To receive the data in the DetailsScreen, you would extract the arguments from the ModalRoute:

class DetailsScreen extends StatelessWidget {
  Widget build(BuildContext context) {
    // Extract the arguments from the current ModalRoute settings and cast them to the correct type
    final String data = ModalRoute.of(context).settings.arguments;

    return Scaffold(
      appBar: AppBar(
        title: Text(‘Details Screen’),
      body: Center(
        child: Text(data),

This setup enables the flexible and efficient passing of data between screens, enhancing the interactivity and functionality of your Flutter app.

State Management

Introduction to State Management

State management refers to how you design, manage, and expose the state of your app’s data to its UI in a way that is easy to reason about. State can include user preferences, app settings, cache data, or any other information that needs to be preserved during navigation and between app sessions.

Why State Management?

Proper state management helps in creating a robust app architecture that separates the app’s logic from its UI, making it easier to debug, test, and scale your app.


ScopedModel is a straightforward library that allows widgets to access shared data models from their ancestor in the widget tree, facilitating easy data passing and state management across the app.

  • How it Works: You wrap your app in a ScopedModel widget, passing it a model. Descendant widgets that need access to the model can use the ScopedModelDescendant widget to rebuild when the model updates.
  • Use Case: ScopedModel is suitable for simpler apps with a less complex data model that needs to be shared across many parts of the app.


Provider is a recommended approach by the Flutter team for state management. It simplifies data flow in your application and provides a scalable way to manage the app state.

  • How it Works: Provider works by exposing data and services to the widget tree, allowing widgets to subscribe to updates. It leverages the concept of “listening” to objects and rebuilding widgets when necessary.
  • Use Case: Provider is versatile and can handle various state management needs, from simple to complex scenarios. It’s particularly useful for medium to large apps requiring scalable state management solutions.


Bloc (Business Logic Component) is an advanced state management library that separates business logic from presentation logic, focusing on stream-based state management.

  • How it Works: Bloc relies on streams and sinks to manage the app’s state. It uses Events to trigger state changes, which are then output as States through Streams. Widgets listen to these state changes and rebuild accordingly.
  • Use Case: Bloc is ideal for complex apps with extensive business logic, requiring a clean separation between the app’s data layer and UI. It’s great for apps that need to maintain clear, testable, and scalable code.

Choosing a State Management Approach

Selecting the right state management solution depends on several factors, including your app’s complexity, your development team’s experience, and your project’s specific requirements.

  • For Simplicity: If you’re building a simple app or just starting with Flutter, consider using Provider for its balance between simplicity and flexibility.
  • For Medium to Complex Apps: For apps with more complex data flows or larger scale projects, Bloc offers a structured approach that keeps your codebase more organized and maintainable.
  • Experiment and Learn: Each project has unique requirements, and there’s no one-size-fits-all solution. Experiment with different approaches to understand their strengths and how they fit into your project.

Tutorial 2: Flutter – Environment Setup


Setting up your environment for Flutter development is straightforward, but before you begin, make sure you meet the following prerequisites:

Operating System Compatibility

Flutter supports several operating systems for development. Whether you’re using Windows, macOS, or Linux, you can develop apps with Flutter.

However, specific versions of these operating systems are supported:

  • Windows: Windows 7 SP1 or later (64-bit), x86-64 based.
  • macOS: macOS (64-bit).
  • Linux: Most distributions are supported.

Hardware Requirements

To run Flutter and the associated Android or iOS emulators smoothly, your development machine should meet specific hardware criteria:

  • Disk Space: A minimum of 64 GB of free disk space is required for the Flutter SDK and its dependencies, though more is recommended for your projects.
  • Tools: For Windows and Linux, you’ll need Git for Windows or Git for Linux to clone the Flutter repo. macOS users will have Git pre-installed.
  • Processor and Memory: While Flutter can run on most modern CPUs, a decent processor and at least 4GB of RAM are recommended for a smooth experience, especially when using emulators.

Software Dependencies

Flutter relies on a few software dependencies to work correctly:

  • Flutter SDK: The core of Flutter development, containing the Flutter engine, framework, and tools.
  • Android Studio or Visual Studio Code: Though you can use any text editor, Android Studio and Visual Studio Code offer excellent Flutter plugin support for a more integrated experience.
  • Dart Plugin: Required for code analysis, completion, and other features.
  • Flutter Plugin: Adds Flutter-specific functionality to your IDE.

Knowledge Requirements

While prior programming experience is not strictly necessary to start learning Flutter, familiarity with object-oriented programming languages like Java, C#, or similar is beneficial. Understanding basic programming concepts such as variables, loops, and conditionals will help you quickly grasp Flutter concepts.

Downloading Flutter SDK


Minimum System Requirements

  • OS: Windows 7 10 (64-bit), x86-64 based.
  • Disk Space:64 GB (does not include disk space for IDE/tools).
  • Tools: Git for Windows 2.x, with the Use Git from the Windows Command Prompt option.


  • Visit the official Flutter website and navigate to the Windows install section.
  • Download the latest stable release of the Flutter SDK as a zip file.
  • Extract the zip file to a desired location on your system (e.g., C:\src\flutter; avoid using directories like C:\Program Files that require elevated permissions).
  • Update your system’s PATH environment variable to include the path to Flutter’s bin directory.
  • Verify the installation by opening a command prompt and running flutter doctor.


Minimum System Requirements

  • OS: macOS (64-bit).
  • Disk Space:8 GB (does not include disk space for IDE/tools).
  • Tools: Git for macOS and bash; these tools typically come pre-installed.


  • Visit the official Flutter website and find the macOS install section.
  • Download the latest stable Flutter SDK release for macOS as a zip file.
  • Extract the file to your desired location (e.g., ~/development/flutter).
  • Open a terminal window and add Flutter to your PATH environment variable.
  • Run flutter doctor in the terminal to check for any dependencies you need to install to complete the setup.

$ flutter doctor


Minimum System Requirements

  • OS: Linux (64-bit).
  • Disk Space:64 GB (does not include disk space for IDE/tools).
  • Tools: Git for Linux, bash, mkdir, rm, unzip, which, xz-utils, and curl.


  • Go to the official Flutter website and locate the Linux install section.
  • Download the latest stable version of the Flutter SDK for Linux.
  • Extract the SDK to a preferred location (e.g., ~/development/flutter).
  • Add Flutter’s bin directory to your PATH environment variable.
  • In the terminal, run flutter doctor to check your environment and see if any additional dependencies are required.

$ flutter doctor

Updating Your Path


  1. Search for ‘Environment Variables‘ in your Start menu and select “Edit the system environment variables.”
  2. In the System Properties window, click on the “Environment Variables” button.
  3. Under “System Variables,” scroll and find the “Path” variable, then click “Edit.”
  4. In the “Edit Environment Variable” window, click “New” and add the full path to the Flutter bin directory. This is the directory inside your Flutter installation folder (e.g., C:\src\flutter\bin).
  5. Click “OK” to close each window.
  6. To verify the addition, open a new command prompt and enter flutter –version. If Flutter is correctly added to your PATH, you should see the Flutter version displayed.

macOS and Linux

The process for macOS and Linux involves editing your shell’s profile script.

  1. Open a terminal.
  2. Determine which shell you are using by running echo $SHELL.
  3. Based on your shell (e.g., bash or zsh), edit the appropriate profile file (.bash_profile, .bashrc, .zshrc, etc.) in your home directory. You can use a text editor like nano (e.g., nano ~/.bash_profile for bash).
  4. Add the export command to the end of the file. For example, if you installed Flutter to ~/development/flutter, add the following line:

export PATH=”$PATH:`pwd`/flutter/bin”

Note: If you’re using Linux and the above command doesn’t work, try replacing `pwd` with the actual path to your Flutter directory, so it looks like:

export PATH=”$PATH:/home/username/development/flutter/bin”

5. Save the file and close the editor.

6. To make the changes take effect, run source ~/<profile file> (e.g., source ~/.bash_profile).

7. Verify the setup by typing flutter –version in the terminal. You should see the installed Flutter version.

Flutter SDK Setup

Once you’ve installed Flutter and updated your PATH, the next step is to finalize your Flutter SDK setup. This will make sure that all components of the Flutter SDK are correctly installed and configured.

Flutter provides a helpful command, flutter doctor, which checks your environment and displays a report to the terminal window about the status of your Flutter installation.

Here’s how to run it and interpret its output.

Running flutter doctor

  1. Open a command prompt on Windows or a terminal on macOS and Linux.
  2. Type flutter doctor and press Enter. The command audits your environment and displays a report in the terminal window.

$ flutter doctor

The output from flutter doctor checks for several things:

  • Flutter SDK Version: Confirms the currently installed version of Flutter.
  • Android toolchain: Verifies the installation of Android Studio, Android SDK, and platform tools required for developing Flutter apps for Android.
  • iOS toolchain: (macOS only) Checks for Xcode, Xcode command-line tools, and iOS simulator availability for iOS development.
  • Chrome: Confirms the availability of Chrome for running web applications.
  • Connected Device: Lists any connected devices or running emulators/simulators.

Interpreting the Output

  • A checkmark (✓) indicates that a check passed successfully.
  • An exclamation mark (!) highlights warnings, such as missing optional components or recommendations for improving your setup.
  • A cross (✗) indicates a problem that needs to be resolved for Flutter to function correctly.

If any issues are detected (marked with ✗), the flutter doctor often provides instructions on how to address them. This may involve installing missing software, accepting license agreements, or configuring your environment further.

Common Fixes Based on flutter doctor Output

  • Android Studio Not Found: Ensure Android Studio is installed and correctly detected. You should set the ANDROID_HOME environment variable or use the Flutter config command to set the Android SDK path.
  • Xcode Not Found: (macOS only) Make sure Xcode is installed, and you’ve run it at least once to install additional components. Also, set the command-line tools in Xcode
  • No Connected Devices: Start an emulator or connect a physical device to your computer. For Android, you can manage emulators via Android Studio’s AVD Manager. For iOS, use the Simulator app available within Xcode.

Running a flutter doctor is a good practice whenever you encounter issues during Flutter development, as it can quickly diagnose common problems. Successfully addressing all issues reported by flutter doctor means your development environment is correctly set up, and you’re ready to start creating Flutter apps.

Setting Up the Android Emulator

Installing Android Studio

 1. Download Android Studio: Go to the official Android Studio website and download the installer for your operating system (Windows, macOS, or Linux).

2. Run the Installer:

    • Windows: Launch the downloaded .exe file and follow the installation prompts. Ensure the boxes for Android SDK, Android SDK Platform, and Android Virtual Device are checked.
    • macOS: Open the downloaded .dmg file, drag and drop Android Studio into the Applications folder, and follow the setup wizard.
    • Linux: Unpack the .zip file you downloaded to your preferred location and execute the studio.sh script found in the android-studio/bin/ directory to start the setup wizard.

3. Follow Setup Wizard: Upon first launching Android Studio, the setup wizard will guide you through the initial setup, including downloading the Android SDK components. Make sure to accept the licenses for the Android SDK.

Creating a Virtual Device

  1. Open the AVD Manager: Navigate to Tools > AVD Manager in Android Studio. The Android Virtual Device (AVD) Manager is where you can create and manage your virtual devices.
  2. Create a New Virtual Device: Click on the “Create Virtual Device” button. Choose a device definition that matches the type of device you want to simulate (e.g., Pixel 4). Then click “Next.”
  3. Select a System Image: You’ll need to download a system image for the emulator. Pick an image with the API level you wish to test against (it’s a good idea to test against the minimum version your app supports). If you haven’t downloaded a system image yet, click the “Download” link next to the system image you want to use. After downloading, select the image and click “Next.”
  4. Configure the Virtual Device: Give your AVD a name, and adjust any settings, such as the orientation, scale, or hardware profile. Once configured to your liking, click “Finish.”
  5. Launch Your Virtual Device: Back in the AVD Manager, you’ll see your newly created virtual device listed. Click the green play button under the “Actions” column to start the emulator.

Setting Up the iOS Simulator (macOS only)

For Flutter developers using macOS, setting up the iOS Simulator is an essential part of the development process, allowing you to test your applications on different versions of iOS and various Apple devices without needing physical hardware. This setup requires installing Xcode, which includes the iOS Simulator.

Installing Xcode

  1. Download Xcode: Open the App Store on your Mac, search for Xcode, and click “Install.” Xcode is Apple’s Integrated Development Environment (IDE) for macOS, containing a suite of software development tools for developing software for macOS, iOS, watchOS, and tvOS.
  2. Accept the License Agreement: Launch Xcode from your Applications folder after installation. You may be prompted to accept the license agreement and install additional components. Enter your Mac’s password if required and allow the installation to complete.
  3. Configure Command Line Tools: Open Xcode, navigate to Xcode > Preferences > Locations tab, and in the “Command Line Tools” dropdown, select the Xcode version you wish to use. This step is essential for using command-line tools and the iOS Simulator.

Using the iOS Simulator

  1. Launch the Simulator: You can start the iOS Simulator directly from Xcode by navigating to Xcode > Open Developer Tool > Simulator. Alternatively, once you’ve run a Flutter app via the command line or your IDE, the iOS Simulator will automatically launch.
  2. Choose Your Device: The iOS Simulator starts with a default device. To change the device, go to Hardware > Device in the Simulator to select a different model or iOS version. You can download additional system images if needed.
  3. Running Your Flutter App: With the Simulator running, you can execute your Flutter app from your terminal or IDE. Use the command flutter run within your Flutter project directory to build and run your app on the Simulator.

The iOS Simulator is a powerful tool for Flutter development on macOS, offering a convenient and cost-effective way to test the appearance and performance of your applications across Apple’s ecosystem.

Editor Setup

Visual Studio Code

Visual Studio Code (VS Code) is a lightweight but powerful source code editor supporting Flutter development with features like IntelliSense code completion and debugging.

  1. Install Visual Studio Code: Download and install VS Code from the official website.
  2. Install the Flutter and Dart Plugins: Launch VS Code, and go to Extensions (View > Extensions). Search for “Flutter” and install the Flutter extension. This extension automatically installs the Dart plugin as well.
  3. Configure VS Code for Flutter Development: Once installed, open the command palette (View > Command Palette) and type “Flutter” to see available actions. You can create new projects and run and debug Flutter applications directly from VS Code.

Android Studio

Android Studio provides a more integrated environment for Flutter development, especially for Android-specific tasks.

  1. Install Android Studio: If not already installed, download and install Android Studio from the official website.
  2. Install the Flutter and Dart Plugins: Open Android Studio, go to Preferences (File > Settings on Windows/Linux), navigate to Plugins, and search for “Flutter.” Install the Flutter plugin and restart Android Studio. This plugin should prompt you to install the Dart plugin if it’s not already installed.
  3. Configure Android Studio for Flutter Development: With the plugins installed, you can create new Flutter projects run, and debug your applications with the full suite of Android Studio’s development tools.

Creating and Running a Test Flutter App

Creating a New Flutter Project

1. Via Command Line

  • Open a terminal (macOS/Linux) or command prompt (Windows).
  • Navigate to the directory where you want to create your Flutter project.
  • Run the command: flutter create my_flutter_app. Replace my_flutter_app with your desired project name. This command creates a new Flutter project with a default sample app.
  • Navigate into your project directory with cd my_flutter_app.

2. Via Android Studio

  • Open Android Studio and select “Start a new Flutter project.”
  • Choose “Flutter Application” as the project type and click “Next.”
  • Enter your desired project name, and specify the Flutter SDK path (if not auto-detected). Click “Next.”
  • Confirm the package name, and click “Finish.” Android Studio will generate a new Flutter project with a sample app.

3. Via Visual Studio Code

  • Open Visual Studio Code and go to the Explorer view.
  • Click on the “View” menu and select “Command Palette.”
  • Type “Flutter” and select “Flutter: New Project.” Follow the prompts to enter your project name and select a project location.

Running Your Flutter App

1. On a Connected Device or Emulator/Simulator

  • Make sure your chosen device or emulator/simulator is running and detected by your system.
  • Via Command Line: Run flutter run with your project directory as the current directory. This command compiles your app and launches it on the connected device or emulator/simulator.
  • Via Android Studio: Click the ‘Run’ button (green triangle) or select ‘Run > Run‘ from the menu. Choose your target device from the dropdown list.
  • Via Visual Studio Code: Open the command palette and select “Flutter: Launch Emulator.” Then, use the Debug panel to start your app by clicking the “Run” button.

2. Hot Reload

  • As your app is running, you can make changes to the code. Flutter’s Hot Reload feature allows you to see the changes almost instantly without restarting the app. In Android Studio or Visual Studio Code, save your changes, and the app will automatically update. Alternatively, in the command line, press “r” to hot reload changes.

3. View Your App

  • Your app, which displays a simple counter, should now be running on your device or emulator/simulator. You can interact with it by pressing the floating action button to increment the counter.

Troubleshooting Common Setup Issues

1. Flutter SDK Not Found

  • Problem: The system does not recognize flutter commands.
  • Solution: Ensure that you’ve added the Flutter SDK’s bin directory to your system’s PATH environment variable. Verify by opening a new terminal or command prompt window and typing flutter –version. If it doesn’t work, review the steps for updating your PATH and restart your terminal or computer.

2. Android License Status Unknown

  • Problem: Running flutter doctor shows that Android licenses are not accepted.
  • Solution: Run flutter doctor –android-licenses and accept the licenses by pressing ‘y’ when prompted. This issue often occurs after installing the Android SDK but not accepting the license agreements.

3. No Connected Devices

  • Problem: Flutter does not detect a device to run the app on.
  • Solutions:
    • For Emulators/Simulators: Ensure your emulator or simulator is running before executing a flutter run. For Android, you can manage and start emulators from Android Studio’s AVD Manager. For iOS, start the Simulator from Xcode.
    • For Physical Devices: Check that your device is connected via USB and that USB debugging is enabled (Android) or that your device is trusted (iOS). For Android devices, you might also need to install specific drivers for your device.

4. iOS Simulator Not Starting

  • Problem: (macOS only) The iOS Simulator does not launch, or the build fails.
  • Solutions:
    • Ensure Xcode and command-line tools are correctly installed and that you’ve agreed to the Xcode license by running sudo xcodebuild -license in the terminal.
    • Open Xcode > Preferences > Locations and check that the command-line tools option is set.

5. Android Studio Not Detected by Flutter

  • Problem: Flutter does not recognize Android Studio, affecting the ability to run Android emulators.
  • Solution: Make sure Android Studio is correctly installed and, if necessary, manually configure the Android Studio path using flutter config –android-studio-dir “<path-to-your-android-studio-location>”.

6. Dart SDK Not Found

  • Problem: Errors indicate that the Dart SDK is not found, even though Flutter’s SDK includes Dart.
  • Solution: This issue usually indicates a problem with the Flutter SDK installation or PATH configuration. Verify that the Flutter SDK path is correctly added to your PATH environment variable and that the SDK is correctly installed by running flutter doctor.

7. Flutter Doctor Shows Issues After All Fixes

  • Problem: flutter doctor still reports problems after following suggested fixes.
  • Solution: Some issues might be informational and not critical to development. For unresolved problems, refer to the Flutter community forums, Stack Overflow, or the official Flutter GitHub page for specific error messages and advanced troubleshooting.