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);
//functoin to do the important work when the user logs out
static clear() {
pageIndex = 0;
pageController.jumpToPage(0);
}
static int pageIndex = 0;
@ -146,12 +144,9 @@ class NavCubit extends Cubit<NavState> {
const MenuView(),
];
static final PageController pageController = PageController();
void updatePageIndex(int index) {
pageIndex = index;
pageController.animateToPage(index,
duration: const Duration(milliseconds: 150), curve: Curves.easeIn);
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/default_app_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/utils/resource_manager/color_manager.dart';
@ -14,8 +15,15 @@ class AppLayout extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => SpacesCubit(),
),
BlocProvider(
create: (context) => DevicesCubit(),
),
],
child: BlocListener<SpacesCubit, SpacesState>(
listener: (context, state) {
if (state is SpacesError) {

View File

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

View File

@ -33,7 +33,8 @@ class LoginView extends StatelessWidget {
}
},
builder: (context, state) {
return Scaffold(
return SafeArea(
child: Scaffold(
body: Stack(
children: [
Container(
@ -60,13 +61,12 @@ class LoginView extends StatelessWidget {
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: Constants.defaultPadding,
padding: const EdgeInsets.only(
right: Constants.defaultPadding,
left: Constants.defaultPadding,
top: Constants.defaultPadding,
),
child: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
child: Center(
child: Column(
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:flutter/material.dart';
@ -22,257 +22,34 @@ part 'devices_state.dart';
class DevicesCubit extends Cubit<DevicesState> {
DevicesCubit() : super(DevicesInitial()) {
fetchGroups(SpacesCubit.selectedSpace!);
fetchGroups(SpacesCubit.selectedSpace!.id!);
}
static DevicesCubit get(context) => BlocProvider.of(context);
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(),
// ),
];
static List<DevicesCategoryModel>? allCategories;
selectCategory(int index) {
for (var i = 0; i < allCategories.length; i++) {
for (var i = 0; i < allCategories!.length; i++) {
if (i == index) {
allCategories[i].isSelected = true;
allCategories![i].isSelected = true;
} else {
allCategories[i].isSelected = false;
allCategories![i].isSelected = false;
}
}
emit(DevicesCategoryChanged());
}
unselectAllCategories() {
for (var category in allCategories) {
for (var category in allCategories!) {
category.isSelected = false;
}
emit(DevicesCategoryChanged());
}
Widget? get chosenCategoryView {
for (var category in allCategories) {
if (allCategories != null) {
for (var category in allCategories!) {
if (category.isSelected) {
switch (category.type) {
case DeviceType.AC:
@ -292,11 +69,12 @@ class DevicesCubit extends Cubit<DevicesState> {
}
}
}
}
return null;
}
DevicesCategoryModel? get chosenCategory {
for (var category in allCategories) {
for (var category in allCategories!) {
if (category.isSelected) {
return category;
}
@ -305,7 +83,7 @@ class DevicesCubit extends Cubit<DevicesState> {
}
selectDevice(DeviceModel device) {
for (var category in allCategories) {
for (var category in allCategories!) {
if (category.devices != null) {
for (var device in category.devices!) {
if (device.isSelected) {
@ -321,7 +99,7 @@ class DevicesCubit extends Cubit<DevicesState> {
}
DeviceModel? getSelectedDevice() {
for (var category in allCategories) {
for (var category in allCategories!) {
if (category.devices != null) {
for (var device in category.devices!) {
if (device.isSelected) {
@ -356,7 +134,7 @@ class DevicesCubit extends Cubit<DevicesState> {
turnOnOffDevice(DeviceModel device) {
device.status = !device.status!;
DevicesCategoryModel category = allCategories.firstWhere((category) {
DevicesCategoryModel category = allCategories!.firstWhere((category) {
if (category.devices != null) {
return category.devices!.contains(device);
} else {
@ -427,7 +205,7 @@ class DevicesCubit extends Cubit<DevicesState> {
}
clearCategoriesSelection(BuildContext context) {
for (var category in allCategories) {
for (var category in allCategories!) {
category.isSelected = false;
if (category.devices != null) {
for (var device in category.devices!) {
@ -450,16 +228,10 @@ class DevicesCubit extends Cubit<DevicesState> {
}
}
fetchGroups(
SpaceModel space,
) async {
fetchGroups(int spaceId) async {
try {
if (state is! DevicesCategoriesLoading) {
emit(DevicesCategoriesLoading());
allCategories = await DevicesAPI.fetchGroups(space.id!);
} else {
return;
}
allCategories = await DevicesAPI.fetchGroups(spaceId);
emit(DevicesCategoriesSuccess());
} on DioException catch (error) {
emit(

View File

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

View File

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

View File

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

View File

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