mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
Refactor HomeCubit class for better instance management
Create a private static instance variable and refactor methods for better instance management in the HomeCubit class.
This commit is contained in:
@ -23,13 +23,13 @@ class AppLayout extends StatelessWidget {
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => HomeCubit(),
|
||||
create: (context) => HomeCubit.getInstance(),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
),
|
||||
],
|
||||
child: BlocListener<HomeCubit, HomeState>(
|
||||
child: BlocConsumer<HomeCubit, HomeState>(
|
||||
listener: (context, state) {
|
||||
if (state is GetSpacesError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@ -41,42 +41,41 @@ class AppLayout extends StatelessWidget {
|
||||
.popUntil((route) => route.settings.name == Routes.authLogin);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
builder: (context, state) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar:
|
||||
state is GetSpacesLoaded ? const DefaultAppBar() : null,
|
||||
body: const AppBody(),
|
||||
bottomNavigationBar: const DefaultNavBar(),
|
||||
// floatingActionButton: FloatingActionButton(
|
||||
// onPressed: () {
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CustomPageRoute(
|
||||
// builder: (context) =>
|
||||
// const ThreeGangSwitchesView(),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// child: const Icon(Icons.arrow_forward_ios_sharp),
|
||||
// ),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: SafeArea(
|
||||
child: BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
return const Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: DefaultAppBar(),
|
||||
body: AppBody(),
|
||||
bottomNavigationBar: DefaultNavBar(),
|
||||
// floatingActionButton: FloatingActionButton(
|
||||
// onPressed: () {
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CustomPageRoute(
|
||||
// builder: (context) =>
|
||||
// const ThreeGangSwitchesView(),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// child: const Icon(Icons.arrow_forward_ios_sharp),
|
||||
// ),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user