mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 20:44:54 +00:00
Refactor device-related views and add error handling
Refactor device-related views to improve code structure and readability. Add error handling for authentication token in the splash view. Remove unnecessary NavCubit from the app initialization.
This commit is contained in:
@ -17,60 +17,62 @@ class AppBarHomeDropdown extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 10, right: 10),
|
||||
child: DropdownButton(
|
||||
icon: const Icon(
|
||||
Icons.expand_more,
|
||||
color: Colors.black,
|
||||
size: 25,
|
||||
),
|
||||
underline: const SizedBox.shrink(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
value: SpacesCubit.selectedSpace!.id,
|
||||
items: SpacesCubit.spaces.map((space) {
|
||||
return DropdownMenuItem(
|
||||
value: space.id,
|
||||
child: SizedBox(
|
||||
width: 100,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
SvgPicture.asset(
|
||||
Assets.iconsHome,
|
||||
width: 25,
|
||||
height: 25,
|
||||
colorFilter: const ColorFilter.mode(
|
||||
ColorsManager.textPrimaryColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Expanded(
|
||||
child: BodyMedium(
|
||||
text: space.name ?? "??",
|
||||
style: context.bodyMedium.copyWith(
|
||||
fontSize: 15,
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
return SpacesCubit.selectedSpace == null
|
||||
? const Center(child: BodyMedium(text: 'No Home Selected'))
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(left: 10, right: 10),
|
||||
child: DropdownButton(
|
||||
icon: const Icon(
|
||||
Icons.expand_more,
|
||||
color: Colors.black,
|
||||
size: 25,
|
||||
),
|
||||
underline: const SizedBox.shrink(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
value: SpacesCubit.selectedSpace!.id,
|
||||
items: SpacesCubit.spaces!.map((space) {
|
||||
return DropdownMenuItem(
|
||||
value: space.id,
|
||||
child: SizedBox(
|
||||
width: 100,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
SvgPicture.asset(
|
||||
Assets.iconsHome,
|
||||
width: 25,
|
||||
height: 25,
|
||||
colorFilter: const ColorFilter.mode(
|
||||
ColorsManager.textPrimaryColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Expanded(
|
||||
child: BodyMedium(
|
||||
text: space.name ?? "??",
|
||||
style: context.bodyMedium.copyWith(
|
||||
fontSize: 15,
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
SpacesCubit.get(context).selectSpace(SpacesCubit.spaces!
|
||||
.firstWhere((element) => element.id == value));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
SpacesCubit.get(context).selectSpace(SpacesCubit.spaces
|
||||
.firstWhere((element) => element.id == value));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
|
||||
import '../../../../generated/assets.dart';
|
||||
@ -12,7 +12,7 @@ class AppBody extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavCubit, NavState>(
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
@ -28,7 +28,7 @@ class AppBody extends StatelessWidget {
|
||||
),
|
||||
child: BlocConsumer<SpacesCubit, SpacesState>(
|
||||
listener: (context, state) {
|
||||
if (state is SpacesError) {
|
||||
if (state is GetSpacesError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errMessage),
|
||||
@ -37,8 +37,9 @@ class AppBody extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return state is! SpacesLoading || state is! SpaceRoomsLoading
|
||||
? NavCubit.of(context).pages[NavCubit.pageIndex]
|
||||
return state is! GetSpacesLoading ||
|
||||
state is! GetSpaceRoomsLoading
|
||||
? SpacesCubit.get(context).pages[SpacesCubit.pageIndex]
|
||||
: const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
@ -9,27 +9,26 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavCubit, NavState>(
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 20,
|
||||
),
|
||||
child: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
leadingWidth: 150,
|
||||
toolbarHeight: Constants.appBarHeight,
|
||||
leading: SpacesCubit.spaces.isNotEmpty
|
||||
? NavCubit.appBarLeading[
|
||||
NavCubit().bottomNavItems[NavCubit.pageIndex].label]
|
||||
: null,
|
||||
actions: NavCubit.appBarActions[
|
||||
NavCubit().bottomNavItems[NavCubit.pageIndex].label],
|
||||
),
|
||||
);
|
||||
},
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 20,
|
||||
),
|
||||
child: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
leadingWidth: 150,
|
||||
toolbarHeight: Constants.appBarHeight,
|
||||
leading: SpacesCubit.spaces != null
|
||||
? SpacesCubit.spaces!.isNotEmpty
|
||||
? SpacesCubit.appBarLeading[SpacesCubit()
|
||||
.bottomNavItems[SpacesCubit.pageIndex]
|
||||
.label]
|
||||
: null
|
||||
: null,
|
||||
actions: SpacesCubit.appBarActions[
|
||||
SpacesCubit().bottomNavItems[SpacesCubit.pageIndex].label],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -13,9 +13,9 @@ class DefaultNavBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavCubit, NavState>(
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
var cubit = NavCubit.of(context);
|
||||
var cubit = SpacesCubit.get(context);
|
||||
return SizedBox(
|
||||
height: Constants.bottomNavBarHeight,
|
||||
child: BottomNavigationBar(
|
||||
@ -29,7 +29,7 @@ class DefaultNavBar extends StatelessWidget {
|
||||
SpacesCubit.get(context).unselectRoom();
|
||||
}
|
||||
},
|
||||
currentIndex: NavCubit.pageIndex,
|
||||
currentIndex: SpacesCubit.pageIndex,
|
||||
selectedItemColor: ColorsManager.primaryColor,
|
||||
selectedLabelStyle: const TextStyle(
|
||||
color: ColorsManager.primaryColor,
|
||||
|
||||
Reference in New Issue
Block a user