mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 23:32:27 +00:00
Refactor SpaceDetailsDialog to improve title handling and loading/error dialogs
This commit is contained in:
@ -43,12 +43,23 @@ class _SpaceDetailsDialogState extends State<SpaceDetailsDialog> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildTitle(BuildContext context) {
|
||||||
|
return DefaultTextStyle(
|
||||||
|
style: context.textTheme.titleLarge!.copyWith(
|
||||||
|
fontSize: 30,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
child: widget.title,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isCreateMode = widget.spaceModel.uuid.isEmpty;
|
final isCreateMode = widget.spaceModel.uuid.isEmpty;
|
||||||
if (isCreateMode) {
|
if (isCreateMode) {
|
||||||
return SpaceDetailsForm(
|
return SpaceDetailsForm(
|
||||||
title: widget.title,
|
title: _buildTitle(context),
|
||||||
space: SpaceDetailsModel.empty(),
|
space: SpaceDetailsModel.empty(),
|
||||||
onSave: widget.onSave,
|
onSave: widget.onSave,
|
||||||
);
|
);
|
||||||
@ -57,23 +68,23 @@ class _SpaceDetailsDialogState extends State<SpaceDetailsDialog> {
|
|||||||
return BlocBuilder<SpaceDetailsBloc, SpaceDetailsState>(
|
return BlocBuilder<SpaceDetailsBloc, SpaceDetailsState>(
|
||||||
bloc: widget.context.read<SpaceDetailsBloc>(),
|
bloc: widget.context.read<SpaceDetailsBloc>(),
|
||||||
builder: (context, state) => switch (state) {
|
builder: (context, state) => switch (state) {
|
||||||
SpaceDetailsInitial() => _buildLoadingDialog(),
|
SpaceDetailsInitial() => buildLoadingDialog(),
|
||||||
SpaceDetailsLoading() => _buildLoadingDialog(),
|
SpaceDetailsLoading() => buildLoadingDialog(),
|
||||||
SpaceDetailsLoaded(:final spaceDetails) => SpaceDetailsForm(
|
SpaceDetailsLoaded(:final spaceDetails) => SpaceDetailsForm(
|
||||||
title: widget.title,
|
title: _buildTitle(context),
|
||||||
space: spaceDetails,
|
space: spaceDetails,
|
||||||
onSave: widget.onSave,
|
onSave: widget.onSave,
|
||||||
),
|
),
|
||||||
SpaceDetailsFailure(:final errorMessage) => _buildErrorDialog(
|
SpaceDetailsFailure(:final errorMessage) => buildErrorDialog(
|
||||||
errorMessage,
|
errorMessage,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildLoadingDialog() {
|
Widget buildLoadingDialog() {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: widget.title,
|
title: _buildTitle(context),
|
||||||
backgroundColor: ColorsManager.white,
|
backgroundColor: ColorsManager.white,
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: context.screenHeight * 0.3,
|
height: context.screenHeight * 0.3,
|
||||||
@ -83,18 +94,17 @@ class _SpaceDetailsDialogState extends State<SpaceDetailsDialog> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildErrorDialog(String errorMessage) {
|
Widget buildErrorDialog(String errorMessage) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: widget.title,
|
title: _buildTitle(context),
|
||||||
backgroundColor: ColorsManager.white,
|
backgroundColor: ColorsManager.white,
|
||||||
content: Center(
|
content: SelectableText(
|
||||||
child: SelectableText(
|
errorMessage,
|
||||||
errorMessage,
|
textAlign: TextAlign.center,
|
||||||
style: context.textTheme.bodyLarge?.copyWith(
|
style: context.textTheme.bodyLarge?.copyWith(
|
||||||
color: ColorsManager.red,
|
color: ColorsManager.red,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user