mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00

Refactor HTTPInterceptor to handle error responses and add a CustomSnackBar helper to display snack bars. This will improve error handling and user feedback in the application.
91 lines
3.5 KiB
Dart
91 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
|
import 'package:syncrow_app/features/app_layout/view/widgets/app_body.dart';
|
|
import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart';
|
|
import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart';
|
|
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
|
import 'package:syncrow_app/features/auth/model/token.dart';
|
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
|
|
class AppLayout extends StatelessWidget {
|
|
const AppLayout({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocConsumer<AuthCubit, AuthState>(
|
|
listener: (context, state) {
|
|
if (state is AuthError) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(state.message),
|
|
),
|
|
);
|
|
Navigator.of(context)
|
|
.popUntil((route) => route.settings.name == Routes.authLogin);
|
|
}
|
|
},
|
|
builder: (context, state) {
|
|
return BlocProvider(
|
|
create: (context) => HomeCubit.getInstance(),
|
|
child: BlocConsumer<HomeCubit, HomeState>(
|
|
listener: (context, state) async {
|
|
if (state is GetSpacesError) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(state.errMessage),
|
|
),
|
|
);
|
|
Navigator.of(context).popUntil(
|
|
(route) => route.settings.name == Routes.authLogin);
|
|
}
|
|
String? token = await const FlutterSecureStorage()
|
|
.read(key: Token.loginAccessTokenKey);
|
|
if (token == null) {
|
|
// ignore: use_build_context_synchronously
|
|
Navigator.of(context).popAndPushNamed(Routes.authLogin);
|
|
}
|
|
},
|
|
builder: (context, state) {
|
|
return AnnotatedRegion(
|
|
value: SystemUiOverlayStyle(
|
|
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
|
statusBarIconBrightness: Brightness.light,
|
|
),
|
|
child: SafeArea(
|
|
child: Scaffold(
|
|
backgroundColor: ColorsManager.backgroundColor,
|
|
extendBodyBehindAppBar: true,
|
|
extendBody: true,
|
|
appBar: HomeCubit.getInstance().spaces != null
|
|
? 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),
|
|
// ),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|