Flutter State Management: Going from setState to Freezed & StateNotifier with Provider

  Рет қаралды 15,957

Andrea Bizzotto

Andrea Bizzotto

Күн бұрын

Mixing UI and logic inside Flutter widgets is bad. Here's how to refactor a simple app for better separation of concerns, immutability, and type safety using Freezed & State Notifier.
Written tutorial here: 👇👇
codewithandrea.com/videos/flu...
As a bonus, here's a movie app built to compare Provider, flutter_bloc and Riverpod:
github.com/bizz84/movie_app_s...
CONTENTS:
00:00 - Intro
02:03 - Example Starter Project: Create Profile Page with setState
05:59 - ChangeNotifier implementation and its drawbacks
12:07 - Freezed package
15:47 - StateNotifier
16:55 - Using Freezed + StateNotifier + Provider
20:24 - Wrap Up
21:53 - Movie app on GitHub
Join my FREE email course to become a Flutter expert with the best resources, at your own pace: codewithandrea.com/newsletter/
Want more? Check out all my Flutter courses: 👇👇
codewithandrea.com/courses/
Happy coding!

Пікірлер: 34
@nipunmadan1989
@nipunmadan1989 3 жыл бұрын
This must go on official flutter channel. Complex topic explained easily.
@flaasher
@flaasher 3 жыл бұрын
One of the best flutter channels ..... respect :)
@dantong8934
@dantong8934 3 жыл бұрын
Thanks for the tutorial. Very easy and deep understanding.
@aloussase
@aloussase 3 ай бұрын
Im not sure when sealed classes came out, but today id think that is the way to go for modeling state
@akashkashyap8756
@akashkashyap8756 3 жыл бұрын
Great video... thanks for making this...
@SharpSangalli
@SharpSangalli 3 жыл бұрын
Very helpful!
@bashiruibrahim8443
@bashiruibrahim8443 3 жыл бұрын
Wow thank you Sir
@Nackenschelle
@Nackenschelle 2 жыл бұрын
this is f***ing gold, highly appreciated!!
@m.husnulaqib1458
@m.husnulaqib1458 2 жыл бұрын
thanks
@mohamedeltaher1611
@mohamedeltaher1611 3 жыл бұрын
thank u
@alejandrogonzalez5192
@alejandrogonzalez5192 3 жыл бұрын
Hey Andrea, thanks for the tutorial! Would you suggest going for Freezed + StateNotifier for a production app?
@BrendansReasons
@BrendansReasons 2 жыл бұрын
you cut through the crap, thank you
@julienlbrn
@julienlbrn 3 жыл бұрын
👋🏻 Andrea! Thank you for this tutorial. At <a href="#" class="seekto" data-time="866">14:26</a>, I needed to import 'package:flutter/foundation.dart' at the top of the file to make the command line generate the .freezed file. How could it work for you without it?
@KraasRas
@KraasRas 3 жыл бұрын
How did you made the screen cast video on the beginning of your great tutorial?
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
Recorded the app with QuickTime, rendered with Rotato
@KraasRas
@KraasRas 3 жыл бұрын
@@CodeWithAndrea Thank you. It looks really nice
@sumayyariyas8564
@sumayyariyas8564 3 жыл бұрын
Hi.. Could you please share a video how to integrate google fit to flutter app? Really want this.. Thanks in advance
@meansnada
@meansnada 3 жыл бұрын
whats the theme you use? looks amazing
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
Dracula theme
@ashishranjan7586
@ashishranjan7586 2 жыл бұрын
a explaination video of movie app..🥺🥺
@techhublearn1
@techhublearn1 3 жыл бұрын
Sir does the courses on your site give certificate after completion?
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
Yes, all courses come with a completion certificate.
@meshkatshadik
@meshkatshadik 3 жыл бұрын
How can a single StateNotifier class produce two/more different states? Or do I just need the same number of StateNotifier classes for each state? I'm stuck with this problem for around 3 days. Still stuck!
@hameedhabeeblahi576
@hameedhabeeblahi576 3 жыл бұрын
api key file is missing pl
@ericchua3492
@ericchua3492 3 жыл бұрын
I need some help. What if the behavior is this i. Load Profile if any ii. Edit Profile How do you construct the ProfileState and ProfiileModel? I am struggling to have both Load and Edit in the same StateNotifier and how to manage the State (freezed). The unexpected behavior i. load profile ii. tap on save iii. profile saved iv. profile is hidden (profile is already loaded, why can't it stays on the screen??? ) my state freezed as below (not sure should I combine or mixed) @freezed abstract class EditProfileState with _$EditProfileState { // General const factory EditProfileState.error(String errorText) = _Error; // Edit const factory EditProfileState.loading() = _Loading; const factory EditProfileState.success() = _Success; // Load profile const factory EditProfileState.dataInitial() = _DataInitial; const factory EditProfileState.dataLoading() = _DataLoading; const factory EditProfileState.dataLoaded(User user) = _DataLoaded; } Do you have any sample codes to achieve the above? Thanks.
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
I would think the states you need are: - noData - data(user) - loading - error Maybe you should load the initial data from your DB before showing the profile page? Then you can initialize your initial state with noData or data(user) accordingly.
@ericchua3492
@ericchua3492 3 жыл бұрын
@@CodeWithAndrea if i want to edit the profile, upon success which state will it be? data (user) ?
@hameedhabeeblahi576
@hameedhabeeblahi576 3 жыл бұрын
from the code on github, api key file is missing
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
Read the instructions on the README on the GitHub repo
@ilmtvtamil
@ilmtvtamil 3 жыл бұрын
why google didn't hire you yet?
@BrendansReasons
@BrendansReasons 2 жыл бұрын
explanation of maybeWhen at <a href="#" class="seekto" data-time="1170">19:30</a> was unclear to me
@faheemahmadofficial7701
@faheemahmadofficial7701 3 жыл бұрын
dear brother please please please please please please make flutter series for beginners by using latest mini frameworks for like get tax and other and also teachers basic applications building instead of wasting time on dark
Flutter State Management with Riverpod: The Essential Guide
28:38
Andrea Bizzotto
Рет қаралды 26 М.
Flutter State Management: setState, BLoC, ValueNotifier, Provider
15:42
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 21 МЛН
Flutter Bloc & Cubit Tutorial
47:58
Reso Coder
Рет қаралды 120 М.
Flutter Google Expert Says don't use Flutter for Websites
1:00
FilledStacks
Рет қаралды 41 М.
Freezed ❄ - Data Class & Union in One Dart Package
36:28
Reso Coder
Рет қаралды 58 М.
Starter Architecture for Flutter & Firebase Apps
19:41
Andrea Bizzotto
Рет қаралды 40 М.
Set State Method in Flutter - State Management Basics
13:25
Flutter Explained
Рет қаралды 23 М.
Flutter State Management Basics and Useful Resources
4:39
Andrea Bizzotto
Рет қаралды 12 М.
Flutter Animations Course Launch: Enroll Today - Early Access!
5:48
Andrea Bizzotto
Рет қаралды 5 М.
İĞNE İLE TELEFON TEMİZLEMEK!🤯
0:17
Safak Novruz
Рет қаралды 1,7 МЛН
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 63 МЛН
Better Than Smart Phones☠️🤯 | #trollface
0:11
Not Sanu Moments
Рет қаралды 16 МЛН