Skip to content

Instantly share code, notes, and snippets.

@kururu-abdo

kururu-abdo/main.dart

Last active Mar 16, 2020
Embed
What would you like to do?
simple flutter state management with setState and dum class that hold logic
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
Mystate createState() => Mystate();
}
class Mystate extends State<MyApp> {
var counter = Counter();
var currentCount;
@override
initState() {
currentCount = counter.counter;
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
drawer: Drawer(),
appBar:
AppBar(centerTitle: true, title: Text("Simple State Management")),
body: Column(children: [
Center(
child: MyWidget(currentCount),
),
Row(children: [
FlatButton.icon(
icon: Icon(Icons.minimize),
onPressed: () {
counter.decrement();
setState(() {
currentCount = counter.counter;
});
},
label: Text("decrement")),
FlatButton.icon(
icon: Icon(Icons.add),
onPressed: () {
counter.increment();
setState(() {
currentCount = counter.counter;
});
},
label: Text("increment"))
])
]),
),
);
}
}
class MyWidget extends StatelessWidget {
final int numl;
MyWidget(this.numl);
@override
Widget build(BuildContext context) {
return Text('the current count is: $numl',
style: TextStyle(color: Colors.red));
}
}
class Counter {
var counter = 0;
void increment() {
counter++;
}
void decrement() {
counter--;
}
int getCurrentCount() {
return counter;
}
}
class Observer {
Map<dynamic, dynamic> repository = {};
Observer() {
register(Counter, Counter());
}
void register(name, object) {
repository[name] = object;
}
fetch(name) => repository[name];
}
@kururu-abdo

This comment has been minimized.

Copy link
Owner Author

@kururu-abdo kururu-abdo commented Mar 16, 2020

this is simple state management with trying to implement multi Blocs in one app by using third class called "Ovserver"

i will regist all blocs over there by using map

then access the specific bloc by using Provider package

@kururu-abdo

This comment has been minimized.

Copy link
Owner Author

@kururu-abdo kururu-abdo commented Mar 16, 2020

contact me at google : wdalhajana50@gmail.com.
whatsapp: 249966302389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment