mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 11:17:55 +00:00
initialized Dashboard Page
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../model/device_model.dart';
|
||||
|
||||
part 'devices_state.dart';
|
||||
|
||||
class DevicesCubit extends Cubit<DevicesState> {
|
||||
DevicesCubit() : super(DevicesInitial()) {
|
||||
getDevices();
|
||||
}
|
||||
|
||||
//TODO separate the navigation logic to another cubit
|
||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
var devices = <DeviceModel>[];
|
||||
|
||||
Future<List<DeviceModel>> getDevices() async {
|
||||
emit(DevicesLoading());
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
emit(DevicesSuccess());
|
||||
|
||||
return devices = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
part of 'devices_cubit.dart';
|
||||
|
||||
@immutable
|
||||
abstract class DevicesState {}
|
||||
|
||||
class DevicesInitial extends DevicesState {}
|
||||
|
||||
class DevicesLoading extends DevicesState {}
|
||||
|
||||
class DevicesSuccess extends DevicesState {}
|
||||
|
||||
class DevicesFailure extends DevicesState {}
|
||||
|
||||
class ChangeIndex extends DevicesState {}
|
||||
@@ -0,0 +1 @@
|
||||
class DeviceModel {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
||||
|
||||
class DevicesView extends StatelessWidget {
|
||||
const DevicesView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) => const DevicesViewBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../bloc/devices_cubit.dart';
|
||||
import 'no_devices_view.dart';
|
||||
|
||||
class DevicesViewBody extends StatelessWidget {
|
||||
const DevicesViewBody({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return DevicesCubit.get(context).devices.isEmpty
|
||||
? const NoDevicesView()
|
||||
: const SizedBox();
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_text_button.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/assets_manager.dart';
|
||||
|
||||
class NoDevicesView extends StatelessWidget {
|
||||
const NoDevicesView({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
ImageManager.boxEmpty,
|
||||
opacity: const AlwaysStoppedAnimation(0.5),
|
||||
scale: 1,
|
||||
width: 140,
|
||||
),
|
||||
const Gap(15),
|
||||
const Text(
|
||||
'No Devices',
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
const Gap(15),
|
||||
const DefaultTextButton(
|
||||
text: 'Add Device',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user