mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 01:14:54 +00:00
connected all apis , create functionality is working
This commit is contained in:
106
lib/features/scene/widgets/create_scene_save_button.dart
Normal file
106
lib/features/scene/widgets/create_scene_save_button.dart
Normal file
@ -0,0 +1,106 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/helper/scene_logic_helper.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class CreateSceneSaveButton extends StatefulWidget {
|
||||
const CreateSceneSaveButton({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CreateSceneSaveButton> createState() => _CreateSceneSaveButtonState();
|
||||
}
|
||||
|
||||
class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
with SceneLogicHelper {
|
||||
late TextEditingController sceneNameController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
sceneNameController = TextEditingController();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
sceneNameController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<CreateSceneBloc, CreateSceneState>(
|
||||
listener: (context, state) {
|
||||
if (state is CreateSceneWithTasks) {
|
||||
if (state.success == true) {
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene created successfully',
|
||||
icon: const Icon(
|
||||
Icons.check,
|
||||
color: Colors.green,
|
||||
),
|
||||
);
|
||||
sceneNameController.text = '';
|
||||
}
|
||||
} else if (state is CreateSceneError) {
|
||||
context.showCustomSnackbar(
|
||||
message: state.message,
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return DefaultButton(
|
||||
onPressed: () {
|
||||
context.customAlertDialog(
|
||||
alertBody: Padding(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: SearchBar(
|
||||
controller: sceneNameController,
|
||||
elevation: WidgetStateProperty.all(0),
|
||||
textStyle: WidgetStateProperty.all(context.bodyMedium),
|
||||
hintStyle: WidgetStateProperty.all(
|
||||
context.bodyMedium.copyWith(
|
||||
fontSize: 14,
|
||||
color: ColorsManager.secondaryTextColor),
|
||||
),
|
||||
hintText: 'Enter scene name',
|
||||
backgroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.backgroundColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: 'Scene Name',
|
||||
onConfirm: () {
|
||||
if (sceneNameController.text.isNotEmpty) {
|
||||
final tasks = context.read<CreateSceneBloc>().tasksList;
|
||||
handleSaveButtonPress(context, sceneNameController, tasks);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
customButtonStyle: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all<Color>(
|
||||
ColorsManager.primaryColorWithOpacity,
|
||||
),
|
||||
),
|
||||
isLoading: state is CreateSceneLoading,
|
||||
child: BodyLarge(
|
||||
text: 'Save',
|
||||
style: context.bodyLarge.copyWith(color: Colors.white),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user