morpheme_base 1.2.1 morpheme_base: ^1.2.1 copied to clipboard
MorphemeBase is base for UI project include state management with cubit.
import 'package:example/cubit/main_cubit.dart';
import 'package:flutter/material.dart';
import 'package:morpheme_base/morpheme_base.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MainPage(title: 'Flutter Demo Home Page'),
);
}
}
class MainPage extends StatefulWidget {
const MainPage({super.key, required this.title});
final String title;
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage>
with MorphemeStatePage<MainPage, MainCubit> {
@override
MainCubit setCubit() => MainCubit();
@override
Widget buildWidget(BuildContext context) {
final counter =
context.select((MainCubit element) => element.state.counter);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: cubit.increment,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}