mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-08-23 22:16:31 +08:00

Co-authored-by: A HEAD FULL OF DREAMS <workdeveloper@gmail.com> Co-authored-by: Nishant Srivastava <nisrulz@users.noreply.github.com>
58 lines
1.5 KiB
Dart
58 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'counter.dart'; // Import the Counter
|
|
|
|
final counter = Counter(); // Instantiate the store
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'MobX',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
home: const MyHomePage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatelessWidget {
|
|
const MyHomePage();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('MobX Stateless Widget Counter'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text(
|
|
'You have pushed the button this many times:',
|
|
),
|
|
// Wrapping in the Observer will automatically re-render on changes to counter.value
|
|
Observer(
|
|
builder: (_) => Text(
|
|
'${counter.value}',
|
|
style: Theme.of(context).textTheme.headline4,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: counter.increment,
|
|
tooltip: 'Increment',
|
|
child: Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
} |