BLoC Is Moving Biz Logic From

BLoC Is Moving Biz Logic From

BLoC does not get rid of the combined controller and view in extends State<MyWidget>. Instead it sets up a Model-View that is bound to the State class to handle most of the controller logic that we would put in the non BLoC State class.

/// {@template bloc_base} /// An interface for the core functionality implemented by /// both [Bloc] and [Cubit]. /// {@endtemplate} abstract class BlocBase<State> implements StateStreamableSource<State>, Emittable<State>, ErrorSink { /// {@macro bloc_base} BlocBase(this._state) { // ignore: invalid_use_of_protected_member _blocObserver.onCreate(this); } // ignore: deprecated_member_use_from_same_package final _blocObserver = BlocOverrides.current?.blocObserver ?? Bloc.observer; late final _stateController = StreamController<State>.broadcast(); State _state; bool _emitted = false; @override State get state => _state; @override Stream<State> get stream => _stateController.stream; /// Whether the bloc is closed. /// /// A bloc is considered closed once [close] is called. /// Subsequent state changes cannot occur within a closed bloc. @override bool get isClosed => _stateController.isClosed; /// Updates the [state] to the provided [state]. /// [emit] does nothing if the [state] being emitted /// is equal to the current [state]. /// /// To allow for the possibility of notifying listeners of the initial state, /// emitting a state which is equal to the initial state is allowed as long /// as it is the first thing emitted by the instance. /// /// * Throws a [StateError] if the bloc is closed. @protected @visibleForTesting @override void emit(State state) { try { if (isClosed) { throw StateError('Cannot emit new states after calling close'); } if (state == _state && _emitted) return; onChange(Change<State>(currentState: this.state, nextState: state)); _state = state; _stateController.add(_state); _emitted = true; } catch (error, stackTrace) { onError(error, stackTrace); rethrow; } } /// Called whenever a [change] occurs with the given [change]. /// A [change] occurs when a new `state` is emitted. /// [onChange] is called before the `state` of the `cubit` is updated. /// [onChange] is a great spot to add logging/analytics for a specific `cubit`. /// /// **Note: `super.onChange` should always be called first.** /// ```dart /// @override /// void onChange(Change change) { /// // Always call super.onChange with the current change /// super.onChange(change); /// /// // Custom onChange logic goes here /// } /// ``` /// /// See also: /// /// * [BlocObserver] for observing [Cubit] behavior globally. /// @protected @mustCallSuper void onChange(Change<State> change) { // ignore: invalid_use_of_protected_member _blocObserver.onChange(this, change); } /// Reports an [error] which triggers [onError] with an optional [StackTrace]. @protected @mustCallSuper @override void addError(Object error, [StackTrace? stackTrace]) { onError(error, stackTrace ?? StackTrace.current); } /// Called whenever an [error] occurs and notifies [BlocObserver.onError]. /// /// **Note: `super.onError` should always be called last.** /// /// ```dart /// @override /// void onError(Object error, StackTrace stackTrace) { /// // Custom onError logic goes here /// /// // Always call super.onError with the current error and stackTrace /// super.onError(error, stackTrace); /// } /// ``` @protected @mustCallSuper void onError(Object error, StackTrace stackTrace) { // ignore: invalid_use_of_protected_member _blocObserver.onError(this, error, stackTrace); } /// Closes the instance. /// This method should be called when the instance is no longer needed. /// Once [close] is called, the instance can no longer be used. @mustCallSuper @override Future<void> close() async { // ignore: invalid_use_of_protected_member _blocObserver.onClose(this); await _stateController.close(); } }

That is the BLoC base class with State bound to it. Subscribe to my substack to go beyond the non clear Flutter Docs.

Free

Flutter Localization Without Writing It Twice

Google's Flutter SDK way of locaization has you writing code

twice. There is a better way that the Flutter GDE's are not covering.

https://fredgrott.substack.com/p/flutter-localization-without-writing

Material Design Holes In Flutter SDK And The Fix

Every edition of Material Design has implementation holes that the

Flutter SDK and GDE's do not cover.

https://fredgrott.substack.com/p/material-design-holes-in-flutter

A Design And DevOPS Way Of Generating Flutter Launch Icons

As of Android 12 the way to get native splash is to auto generate

the launch icons. This is a better way to do it and includes how

to generate the Material You launch monochrome icons.

https://fredgrott.substack.com/p/a-design-and-devops-way-of-generating

Beating M3 IN A Flutter Dev Machine

This is the intel way to out perform Apple M-silicon.

https://fredgrott.substack.com/p/beating-m3-in-a-flutter-dev-machine

How To Implement Observable Flutter Logging

This is how to get full application logging beyond the debug mode.

https://fredgrott.substack.com/p/how-to-implement-observable-flutter

Better App Exceptions Catching Than The Flutter SDK

A better way to catch application exceptions that extends

the Flutter SDK way of catching exceptions.

https://fredgrott.substack.com/p/better-app-exceptions-catching-than

Flutter Static Code Analysis Tools To Pair For DevOPS

The best way to judge code architecture decisions is through

these static analysis tools.

https://fredgrott.substack.com/p/flutter-static-code-analysis-tools

What ADHD Designers Are Hding From You About Super Focus

A better way to code and design focus.

https://fredgrott.substack.com/p/what-adhd-designers-are-hiding-from

How To Implement Flutter Staggered Animations

Staggered animation of container contents is in the Material

Design 3 spec but not the flutter SDK. This is one of the

ways to get staggered animations.

https://fredgrott.substack.com/p/how-to-implement-flutter-staggered

New In Flutter 3 Sliver Axis Groups

This is some new Sliver layout tools that made it into the Flutter SDK.

https://fredgrott.substack.com/p/new-in-flutter-3-sliver-axis-groups

Why The Flutter SDK Sucks

The pain of dealing with the fast developing Flutter SDK.

https://fredgrott.substack.com/p/why-the-flutter-sdk-sucks

What StoryBoarding In Flutter Will Google introduce At IO 2024

This the only storyboarding package in which you get to use the

same code to do BDD unit testing. So it is a must read.

https://fredgrott.substack.com/p/what-storyboarding-in-flutter-will

Design The Data Class Model Instead Of Coding It

This complements using Stager as your storyboard library in that

mock methods should always be in your Models.

https://fredgrott.substack.com/p/design-the-data-class-model-instead

How To Write Flutter Adaptive Scaffold Breakpoints Like You Were A GDE

First step to writing an adaptive scaffold is coding Material Design 3

breakpoints since they are not in the Flutter SDK.

https://fredgrott.substack.com/p/how-to-write-flutter-adaptive-scaffold

Fixing Flutter Surface Color Roles

Material Design 3 spec recently changed to having surface color roles.

This is a way to implement them before the Flutter SDK has them.

https://fredgrott.substack.com/p/fixing-flutter-surface-color-roles

Flutter GDE Way To Code A Side Sheet

One of the changes from Material Design 2 to Material Design 3 is that

the navigation drawers are now wrapped in side sheets.

https://fredgrott.substack.com/p/flutter-gde-way-to-code-a-side-sheet

Secret Scroll tweak Not In The Flutter Docs

While we do not want scroll in our fields we need to locally

refix scroll for the non mobile platforms, this is how to do that.

https://fredgrott.substack.com/p/secret-scrollable-tweak-not-in-the

Playing With PageView Scroll Physics

Differnt pageview scroll physics you can implement.

https://fredgrott.substack.com/p/playing-with-pageview-scroll-physics

Parallax Via Flutter Scrollable

Its parallaxs effect is all tied to the scrollable.

https://fredgrott.substack.com/p/parallax-via-flutter-scrollable

Awesome Flutter Theme Animation

This is the way to do using the fact that one can create an image

of what is rendered.

https://fredgrott.substack.com/p/awesome-flutter-theme-animation

How To Get Variable Fonts In Flutter

This is the way to use custom variable fonts in flutter.

https://open.substack.com/pub/fredgrott/p/how-to-get-variable-fonts-in-flutter?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Designers Do Not Let Flutter Designers use UseCase classes as Services

Stop abstracting stuff that does not matter such a UseCase classes, please!

https://open.substack.com/pub/fredgrott/p/designers-do-not-let-flutter-designers?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Design Hacking Flutter HCT Color Space

A design twist in getting brand colors into HCT

https://open.substack.com/pub/fredgrott/p/design-hacking-flutter-hct-color?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Do Not Use debugPrint In Flutter

Yes, avoid using print and debugPrint..this is why

https://open.substack.com/pub/fredgrott/p/do-not-use-debugprint-in-flutter?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

How To Upgrade Color Scheme When Material Design Spec Changes

Easy way to upgrade Color Scheme when the spec changes.

https://open.substack.com/pub/fredgrott/p/how-to-upgrade-color-scheme-when?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

PAID

Missing In Flutter SDK Docs Your Axis Layout Guide

This one of the layout guides you need. And the other one is in

process and will be out soon.

https://fredgrott.substack.com/p/missing-in-flutter-sdk-docs-your

IOS Squircle Shapes For Flutter

No, the Flutter SDK shape stadium does not even come close to

matching iOS squircle. This is my implementation of it.

https://fredgrott.substack.com/p/ios-squircle-shapes-for-flutter

Found The Missing Material Design 3 Carousel

Exploration and strategies for implementing the Material Design carousel.

https://fredgrott.substack.com/p/found-the-missing-material-design

Missing From Flutter SDK Material Design 3 Focus Ring

The Material Design 3 focus ring is not in the Flutter SDK.

This is how to implement it.

https://open.substack.com/pub/fredgrott/p/missing-from-flutter-sdk-material?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Fixing Material You Flutter Theming

How to implement themes support the dynamic user chosen color in

Flutter using the Flutter SDK ColorScheme and ThemeData way of doing

it.

https://open.substack.com/pub/fredgrott/p/fixing-material-you-flutter-theming?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Material You Themes Superpwoered With FlexColorScheme

A better way to fill those component themes with dynamic color magic

https://open.substack.com/pub/fredgrott/p/material-you-themes-superpowered?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Missing In Flutter SDK Color Scheme Tone Themes

Material Color Utilities tone variations are not in the Flutter SDK Color Schemes yet, but

you can use Flex Color Scheme instead to get them and many more!

https://open.substack.com/pub/fredgrott/p/missing-in-flutter-sdk-color-scheme?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

Engineering Use Case Canonical Layouts

Mixing Adaptive Scaffold And Canonical Layouts together

https://open.substack.com/pub/fredgrott/p/engineering-use-case-canonical-layouts?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

An Engineering Challenge Designing A Flutter Adaptive Responsive Scaffold

The flutter SDK does not have this so I have to engineer one

https://open.substack.com/pub/fredgrott/p/an-engineering-challenge-designing?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

MediaQuery Extensions Is The Tool Out Of The Flutter Canonical Layout Mess

Adaptive scaffold and canonical layouts got paired up in MD3 but no solution in

docs or among Flutter GDEs...I instead had to build the tools..

https://open.substack.com/pub/fredgrott/p/media-query-extensions-is-the-tool?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true

A Step Towards Adaptive Responsive Apps The Stateful Shell Route

To break down the complex adaptive scaffold responsive layout pattern,

start with the go router stateful shell route first

https://open.substack.com/pub/fredgrott/p/a-step-towards-adaptive-responsive?r=26egx&utm_campaign=post&utm_medium=web&showWelcome=true


要查看或添加评论,请登录

社区洞察

其他会员也浏览了