Fixed the overflow in the login screen, the page is scrollable.

- Fixed Scrolling wasent working in login screen
- Changed Home page to indexed based view instead of PageView
This commit is contained in:
Mohammad Salameh
2024-03-19 13:29:12 +03:00
parent 79279180df
commit 42051bb977
10 changed files with 148 additions and 373 deletions

View File

@ -17,10 +17,8 @@ class NavCubit extends Cubit<NavState> {
static NavCubit of(context) => BlocProvider.of<NavCubit>(context); static NavCubit of(context) => BlocProvider.of<NavCubit>(context);
//functoin to do the important work when the user logs out
static clear() { static clear() {
pageIndex = 0; pageIndex = 0;
pageController.jumpToPage(0);
} }
static int pageIndex = 0; static int pageIndex = 0;
@ -146,12 +144,9 @@ class NavCubit extends Cubit<NavState> {
const MenuView(), const MenuView(),
]; ];
static final PageController pageController = PageController();
void updatePageIndex(int index) { void updatePageIndex(int index) {
pageIndex = index; pageIndex = index;
pageController.animateToPage(index,
duration: const Duration(milliseconds: 150), curve: Curves.easeIn);
emit(NavChangePage()); emit(NavChangePage());
} }
} }

View File

@ -6,6 +6,7 @@ import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/app_body.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_app_bar.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
@ -14,8 +15,15 @@ class AppLayout extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => SpacesCubit(), create: (context) => SpacesCubit(),
),
BlocProvider(
create: (context) => DevicesCubit(),
),
],
child: BlocListener<SpacesCubit, SpacesState>( child: BlocListener<SpacesCubit, SpacesState>(
listener: (context, state) { listener: (context, state) {
if (state is SpacesError) { if (state is SpacesError) {

View File

@ -38,11 +38,7 @@ class AppBody extends StatelessWidget {
}, },
builder: (context, state) { builder: (context, state) {
return state is! SpacesLoading || state is! SpaceRoomsLoading return state is! SpacesLoading || state is! SpaceRoomsLoading
? PageView( ? NavCubit.of(context).pages[NavCubit.pageIndex]
physics: const NeverScrollableScrollPhysics(),
controller: NavCubit.pageController,
children: NavCubit.of(context).pages,
)
: const Center(child: CircularProgressIndicator()); : const Center(child: CircularProgressIndicator());
}, },
), ),

View File

@ -33,7 +33,8 @@ class LoginView extends StatelessWidget {
} }
}, },
builder: (context, state) { builder: (context, state) {
return Scaffold( return SafeArea(
child: Scaffold(
body: Stack( body: Stack(
children: [ children: [
Container( Container(
@ -60,13 +61,12 @@ class LoginView extends StatelessWidget {
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.only(
horizontal: Constants.defaultPadding, right: Constants.defaultPadding,
left: Constants.defaultPadding,
top: Constants.defaultPadding,
), ),
child: SingleChildScrollView( child: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
child: Center( child: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -99,10 +99,10 @@ class LoginView extends StatelessWidget {
), ),
), ),
), ),
),
) )
], ],
), ),
),
); );
}, },
); );

View File

@ -1,4 +1,4 @@
// ignore_for_file: constant_identifier_names // ignore_for_file: constant_identifier_names, unused_import
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -22,257 +22,34 @@ part 'devices_state.dart';
class DevicesCubit extends Cubit<DevicesState> { class DevicesCubit extends Cubit<DevicesState> {
DevicesCubit() : super(DevicesInitial()) { DevicesCubit() : super(DevicesInitial()) {
fetchGroups(SpacesCubit.selectedSpace!); fetchGroups(SpacesCubit.selectedSpace!.id!);
} }
static DevicesCubit get(context) => BlocProvider.of(context); static DevicesCubit get(context) => BlocProvider.of(context);
static List<DevicesCategoryModel> allCategories = [ static List<DevicesCategoryModel>? allCategories;
// DevicesCategoryModel(
// devices: [
// DeviceModel(
// name: "Living Room AC",
// id: 0,
// functions: [],
// status: false,
// temperature: 20,
// fanSpeed: 0,
// tempMode: 0,
// coolTo: 20,
// type: DeviceType.AC,
// image: '',
// timer: null,
// bounds: Bounds(
// min: 20,
// max: 30,
// ),
// ),
// DeviceModel(
// name: "Master Bedroom AC",
// id: 1,
// functions: [],
// status: false,
// temperature: 20,
// fanSpeed: 0,
// tempMode: 0,
// coolTo: 20,
// type: DeviceType.AC,
// image: '',
// timer: null,
// bounds: Bounds(
// min: 20,
// max: 30,
// ),
// ),
// DeviceModel(
// name: "Kitchen AC",
// id: 2,
// functions: [],
// status: false,
// temperature: 20,
// fanSpeed: 0,
// tempMode: 0,
// coolTo: 20,
// type: DeviceType.AC,
// image: '',
// timer: null,
// bounds: Bounds(
// min: 20,
// max: 30,
// ),
// ),
// DeviceModel(
// name: "Bathroom AC",
// id: 3,
// functions: [],
// status: false,
// temperature: 20,
// fanSpeed: 0,
// tempMode: 0,
// coolTo: 20,
// type: DeviceType.AC,
// image: '',
// timer: null,
// bounds: Bounds(
// min: 20,
// max: 30,
// ),
// ),
// ],
// icon: Assets.iconsAC,
// name: 'ACs',
// type: DeviceType.AC,
// page: const ACsView(),
// ),
// DevicesCategoryModel(
// devices: [
// DeviceModel(
// name: "Living Room Light",
// id: 0,
// functions: [],
// status: false,
// color: 0,
// brightness: 20,
// lightingMode: 1,
// timer: null,
// type: DeviceType.Lights,
// image: '',
// recentColors: [
// 0xFF83D9FF,
// 0xFFFC3E81,
// 0xFFC0FF66,
// 0xFFFDC242,
// ],
// ),
// DeviceModel(
// name: "Master Bedroom Light",
// id: 1,
// functions: [],
// status: false,
// color: 2,
// brightness: 40,
// lightingMode: 1,
// timer: null,
// type: DeviceType.Lights,
// image: '',
// recentColors: [
// 0xFF83D9FF,
// 0xFFFC3E81,
// 0xFFC0FF66,
// 0xFFFDC242,
// ],
// ),
// DeviceModel(
// name: "Kitchen Light",
// id: 2,
// functions: [],
// status: false,
// color: 1,
// brightness: 60,
// lightingMode: 1,
// timer: null,
// type: DeviceType.Lights,
// image: '',
// recentColors: [
// 0xFF83D9FF,
// 0xFFFC3E81,
// 0xFFC0FF66,
// 0xFFFDC242,
// ],
// ),
// DeviceModel(
// name: "Bathroom Light",
// id: 3,
// functions: [],
// status: false,
// color: 3,
// brightness: 80,
// lightingMode: 1,
// timer: null,
// type: DeviceType.Lights,
// image: '',
// recentColors: [
// 0xFF83D9FF,
// 0xFFFC3E81,
// 0xFFC0FF66,
// 0xFFFDC242,
// ],
// ),
// DeviceModel(
// name: "Balcony Light",
// id: 4,
// functions: [],
// status: false,
// color: 4,
// brightness: 100,
// lightingMode: 1,
// timer: null,
// type: DeviceType.Lights,
// image: '',
// recentColors: [
// 0xFF83D9FF,
// 0xFFFC3E81,
// 0xFFC0FF66,
// 0xFFFDC242,
// ],
// ),
// ],
// icon: Assets.iconsLight,
// name: 'Lights',
// type: DeviceType.Lights,
// page: const LightsView(),
// ),
// DevicesCategoryModel(
// devices: [],
// icon: Assets.iconsDoorLock,
// name: 'Doors',
// type: DeviceType.DoorLock,
// page: const DoorView(),
// ),
// DevicesCategoryModel(
// devices: [
// DeviceModel(
// openPercentage: 10,
// id: 1,
// functions: [],
// name: "Living Room Curtain",
// status: false,
// type: DeviceType.Curtain,
// image: '',
// timer: null,
// ),
// DeviceModel(
// openPercentage: 20,
// id: 2,
// functions: [],
// name: "Master Bedroom Curtain",
// status: false,
// type: DeviceType.Curtain,
// image: '',
// timer: null,
// ),
// ],
// icon: Assets.iconsCurtain,
// name: 'Curtains',
// type: DeviceType.Curtain,
// page: const CurtainView(),
// ),
// DevicesCategoryModel(
// devices: [],
// icon: Assets.icons3GangSwitch,
// name: 'Bedroom Lights',
// type: DeviceType.ThreeGang,
// page: const LightSwitchesView(),
// ),
// DevicesCategoryModel(
// devices: [],
// icon: Assets.iconsGateway,
// name: 'Gateway',
// type: DeviceType.Gateway,
// page: const GateWayView(),
// ),
];
selectCategory(int index) { selectCategory(int index) {
for (var i = 0; i < allCategories.length; i++) { for (var i = 0; i < allCategories!.length; i++) {
if (i == index) { if (i == index) {
allCategories[i].isSelected = true; allCategories![i].isSelected = true;
} else { } else {
allCategories[i].isSelected = false; allCategories![i].isSelected = false;
} }
} }
emit(DevicesCategoryChanged()); emit(DevicesCategoryChanged());
} }
unselectAllCategories() { unselectAllCategories() {
for (var category in allCategories) { for (var category in allCategories!) {
category.isSelected = false; category.isSelected = false;
} }
emit(DevicesCategoryChanged()); emit(DevicesCategoryChanged());
} }
Widget? get chosenCategoryView { Widget? get chosenCategoryView {
for (var category in allCategories) { if (allCategories != null) {
for (var category in allCategories!) {
if (category.isSelected) { if (category.isSelected) {
switch (category.type) { switch (category.type) {
case DeviceType.AC: case DeviceType.AC:
@ -292,11 +69,12 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
} }
} }
}
return null; return null;
} }
DevicesCategoryModel? get chosenCategory { DevicesCategoryModel? get chosenCategory {
for (var category in allCategories) { for (var category in allCategories!) {
if (category.isSelected) { if (category.isSelected) {
return category; return category;
} }
@ -305,7 +83,7 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
selectDevice(DeviceModel device) { selectDevice(DeviceModel device) {
for (var category in allCategories) { for (var category in allCategories!) {
if (category.devices != null) { if (category.devices != null) {
for (var device in category.devices!) { for (var device in category.devices!) {
if (device.isSelected) { if (device.isSelected) {
@ -321,7 +99,7 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
DeviceModel? getSelectedDevice() { DeviceModel? getSelectedDevice() {
for (var category in allCategories) { for (var category in allCategories!) {
if (category.devices != null) { if (category.devices != null) {
for (var device in category.devices!) { for (var device in category.devices!) {
if (device.isSelected) { if (device.isSelected) {
@ -356,7 +134,7 @@ class DevicesCubit extends Cubit<DevicesState> {
turnOnOffDevice(DeviceModel device) { turnOnOffDevice(DeviceModel device) {
device.status = !device.status!; device.status = !device.status!;
DevicesCategoryModel category = allCategories.firstWhere((category) { DevicesCategoryModel category = allCategories!.firstWhere((category) {
if (category.devices != null) { if (category.devices != null) {
return category.devices!.contains(device); return category.devices!.contains(device);
} else { } else {
@ -427,7 +205,7 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
clearCategoriesSelection(BuildContext context) { clearCategoriesSelection(BuildContext context) {
for (var category in allCategories) { for (var category in allCategories!) {
category.isSelected = false; category.isSelected = false;
if (category.devices != null) { if (category.devices != null) {
for (var device in category.devices!) { for (var device in category.devices!) {
@ -450,16 +228,10 @@ class DevicesCubit extends Cubit<DevicesState> {
} }
} }
fetchGroups( fetchGroups(int spaceId) async {
SpaceModel space,
) async {
try { try {
if (state is! DevicesCategoriesLoading) {
emit(DevicesCategoriesLoading()); emit(DevicesCategoriesLoading());
allCategories = await DevicesAPI.fetchGroups(space.id!); allCategories = await DevicesAPI.fetchGroups(spaceId);
} else {
return;
}
emit(DevicesCategoriesSuccess()); emit(DevicesCategoriesSuccess());
} on DioException catch (error) { } on DioException catch (error) {
emit( emit(

View File

@ -27,8 +27,8 @@ class LightsView extends StatelessWidget {
as DeviceModel; as DeviceModel;
} }
List<DeviceModel> lights = []; List<DeviceModel> lights = [];
if (DevicesCubit.allCategories[1].devices != null) { if (DevicesCubit.allCategories![1].devices != null) {
for (var device in DevicesCubit.allCategories[1].devices!) { for (var device in DevicesCubit.allCategories![1].devices!) {
lights.add(device); lights.add(device);
} }
} }

View File

@ -30,7 +30,7 @@ class LightsViewList extends StatelessWidget {
children: [ children: [
const BodySmall(text: "All Lights"), const BodySmall(text: "All Lights"),
UniversalSwitch( UniversalSwitch(
category: DevicesCubit.allCategories[1], category: DevicesCubit.allCategories![1],
), ),
LightsList(lights: lights), LightsList(lights: lights),
], ],

View File

@ -18,10 +18,11 @@ class WizartSwitches extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) { builder: (context, state) {
return state is DevicesLoading return state is! DevicesLoading
? const Center(child: CircularProgressIndicator()) ? DevicesCubit.allCategories != null
: GridView.builder( ? GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisCount: 2,
crossAxisSpacing: 10, crossAxisSpacing: 10,
mainAxisSpacing: 10, mainAxisSpacing: 10,
@ -30,7 +31,7 @@ class WizartSwitches extends StatelessWidget {
padding: const EdgeInsets.only(top: 10), padding: const EdgeInsets.only(top: 10),
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemCount: DevicesCubit.allCategories.length, itemCount: DevicesCubit.allCategories!.length,
itemBuilder: (_, index) { itemBuilder: (_, index) {
return InkWell( return InkWell(
onTap: () { onTap: () {
@ -39,27 +40,30 @@ class WizartSwitches extends StatelessWidget {
Navigator.push(context, Navigator.push(context,
CustomPageRoute(builder: (context) { CustomPageRoute(builder: (context) {
return DevicesCubit.get(context).chosenCategoryView!; return DevicesCubit.get(context)
.chosenCategoryView!;
})); }));
}, },
child: DefaultContainer( child: DefaultContainer(
child: Padding( child: Padding(
padding: padding: const EdgeInsets.only(
const EdgeInsets.only(top: 10, right: 10, left: 10), top: 10, right: 10, left: 10),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
SvgPicture.asset( SvgPicture.asset(
DevicesCubit.allCategories[index].icon!, DevicesCubit.allCategories![index].icon!,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
CustomSwitch( CustomSwitch(
category: DevicesCubit.allCategories[index], category:
DevicesCubit.allCategories![index],
), ),
], ],
), ),
@ -67,7 +71,8 @@ class WizartSwitches extends StatelessWidget {
child: FittedBox( child: FittedBox(
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
child: BodyLarge( child: BodyLarge(
text: DevicesCubit.allCategories[index].name!, text: DevicesCubit
.allCategories![index].name!,
style: context.bodyLarge.copyWith( style: context.bodyLarge.copyWith(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
height: 0, height: 0,
@ -83,6 +88,10 @@ class WizartSwitches extends StatelessWidget {
), ),
); );
}, },
)
: const SizedBox.shrink()
: const Center(
child: CircularProgressIndicator(),
); );
}, },
); );

View File

@ -5,8 +5,6 @@ import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/utils/resource_manager/theme_manager.dart'; import 'package:syncrow_app/utils/resource_manager/theme_manager.dart';
import 'features/devices/bloc/devices_cubit.dart';
import 'navigation/router.dart' as router; import 'navigation/router.dart' as router;
import 'navigation/routing_constants.dart'; import 'navigation/routing_constants.dart';
@ -30,9 +28,6 @@ class MyApp extends StatelessWidget {
lazy: false, lazy: false,
create: (context) => NavCubit(), create: (context) => NavCubit(),
), ),
BlocProvider(
create: (context) => DevicesCubit(),
),
], ],
child: MaterialApp( child: MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,

View File

@ -38,8 +38,8 @@ class HTTPService {
queryParameters: queryParameters, queryParameters: queryParameters,
); );
debugPrint("status code is ${response.statusCode}"); // debugPrint("status code is ${response.statusCode}");
debugPrint("response data is ${response.data}"); // debugPrint("response data is ${response.data}");
return expectedResponseModel(response.data); return expectedResponseModel(response.data);
} catch (error) { } catch (error) {
debugPrint("******* Error"); debugPrint("******* Error");