Member-only story

Flutter global state with states rebuilder package

Maria Papageorgiou
5 min readOct 7, 2021

--

Global state, no boilerplate code and automatically rebuilding UI?

I thought it was too good to be true. With other patterns like BLoC, state management is a daunting, long process. To set up even the most simple app with BLoC takes a lot of writing, at least three code files, and a steep learning curve. Enter states rebuilder package.

This package makes state management a breeze. Let’s take the simple counter app as an example.

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
_counter++;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(

--

--

Maria Papageorgiou
Maria Papageorgiou

Written by Maria Papageorgiou

NYC, Software Developer, “Brilliant, hilarious and charming” — At Least One Person

No responses yet