From c0ba18f69c1e482fd8dd592da259cc7dd1bbd236 Mon Sep 17 00:00:00 2001 From: Shaik Zainab Date: Mon, 29 Sep 2025 17:28:16 +0530 Subject: [PATCH 1/3] snackbar fix --- lib/cubit/canvas_cubit.dart | 46 ++++++++++--------------------- lib/cubit/canvas_state.dart | 7 ----- lib/ui/screens/canvas_screen.dart | 10 +------ 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/lib/cubit/canvas_cubit.dart b/lib/cubit/canvas_cubit.dart index e90309d2..61761280 100644 --- a/lib/cubit/canvas_cubit.dart +++ b/lib/cubit/canvas_cubit.dart @@ -150,12 +150,11 @@ class CanvasCubit extends Cubit { if (savedPath != null) { _updateState(backgroundImagePath: savedPath); - emit( - state.copyWith(message: 'Background image uploaded successfully!')); + CustomSnackbar.showSuccess('Background image uploaded successfully!'); } } catch (e) { log('Error uploading background image: $e'); - emit(state.copyWith(message: 'Error uploading image: $e')); + CustomSnackbar.showError('Error uploading image: $e'); } } @@ -174,12 +173,11 @@ class CanvasCubit extends Cubit { if (savedPath != null) { _updateState(backgroundImagePath: savedPath); - emit( - state.copyWith(message: 'Background photo captured successfully!')); + CustomSnackbar.showSuccess('Background photo captured successfully!'); } } catch (e) { log('Error taking photo for background: $e'); - emit(state.copyWith(message: 'Error taking photo: $e')); + CustomSnackbar.showError('Error taking photo: $e'); } } @@ -191,7 +189,7 @@ class CanvasCubit extends Cubit { } _updateState(clearBackgroundImage: true); - emit(state.copyWith(message: 'Background image removed')); + CustomSnackbar.showInfo('Background image removed'); } // Helper method to save image to app directory @@ -430,14 +428,12 @@ class CanvasCubit extends Cubit { // Set the current page name and emit success message emit(state.copyWith( currentPageName: pageName, - message: 'Page "$pageName" saved successfully!', )); + CustomSnackbar.showSuccess('Page "$pageName" saved successfully!'); } catch (e, stackTrace) { log('โŒ Error saving page: $e'); log('Stack trace: $stackTrace'); - emit(state.copyWith( - message: 'Error saving page: $e', - )); + CustomSnackbar.showError('Error saving page: $e'); } } @@ -463,7 +459,7 @@ class CanvasCubit extends Cubit { if (pageDataString == null) { log('โŒ Page not found: $pageName'); - emit(state.copyWith(message: 'Page "$pageName" not found')); + CustomSnackbar.showError('Page "$pageName" not found'); return; } @@ -523,17 +519,15 @@ class CanvasCubit extends Cubit { backgroundColor: Color(pageData['backgroundColor']), backgroundImagePath: validImagePath, selectedTextItemIndex: null, - message: 'Page "$pageName" loaded successfully!', history: [], future: [], currentPageName: pageName, )); + CustomSnackbar.showSuccess('Page "$pageName" loaded successfully!'); } catch (e, stackTrace) { log('โŒ Error loading page: $e'); log('Stack trace: $stackTrace'); - emit(state.copyWith( - message: 'Error loading page: $e', - )); + CustomSnackbar.showError('Error loading page: $e'); } } @@ -554,8 +548,8 @@ class CanvasCubit extends Cubit { isDrawingMode: false, // Exit drawing mode when creating new page clearCurrentPageName: true, clearBackgroundImage: true, - message: 'New page created', )); + CustomSnackbar.showInfo('New page created'); } // Get list of saved pages @@ -621,19 +615,13 @@ class CanvasCubit extends Cubit { if (state.currentPageName == pageName) { emit(state.copyWith( clearCurrentPageName: true, - message: 'Page "$pageName" deleted successfully!', - )); - } else { - emit(state.copyWith( - message: 'Page "$pageName" deleted successfully!', )); } + CustomSnackbar.showSuccess('Page "$pageName" deleted successfully!'); } catch (e, stackTrace) { log('โŒ Error deleting page: $e'); log('Stack trace: $stackTrace'); - emit(state.copyWith( - message: 'Error deleting page: $e', - )); + CustomSnackbar.showError('Error deleting page: $e'); } } @@ -673,11 +661,6 @@ class CanvasCubit extends Cubit { } } - // Clear message (useful for dismissing notifications) - void clearMessage() { - emit(state.copyWith(message: null)); - } - // Debug method to clear all saved data (now also cleans up image files) Future clearAllSavedData() async { try { @@ -717,12 +700,13 @@ class CanvasCubit extends Cubit { log('๐Ÿงน Cleared all saved data: $keysToRemove'); emit(state.copyWith( - message: 'All saved data cleared!', clearCurrentPageName: true, clearBackgroundImage: true, )); + CustomSnackbar.showSuccess('All saved data cleared!'); } catch (e) { log('โŒ Error clearing saved data: $e'); + CustomSnackbar.showError('Error clearing saved data: $e'); } } diff --git a/lib/cubit/canvas_state.dart b/lib/cubit/canvas_state.dart index 49af8721..2f581520 100644 --- a/lib/cubit/canvas_state.dart +++ b/lib/cubit/canvas_state.dart @@ -12,7 +12,6 @@ class CanvasState { final String? backgroundImagePath; final int? selectedTextItemIndex; final bool isTrayShown; - final String? message; final String? currentPageName; final bool isDrawingMode; final Color currentDrawColor; @@ -28,7 +27,6 @@ class CanvasState { this.backgroundImagePath, this.selectedTextItemIndex, this.isTrayShown = false, - this.message, this.currentPageName, this.isDrawingMode = false, this.currentDrawColor = ColorConstants.dialogTextBlack, @@ -46,7 +44,6 @@ class CanvasState { backgroundImagePath: null, selectedTextItemIndex: null, isTrayShown: false, - message: null, currentPageName: null, isDrawingMode: false, currentDrawColor: ColorConstants.dialogTextBlack, @@ -70,7 +67,6 @@ class CanvasState { Color? currentDrawColor, double? currentStrokeWidth, BrushType? currentBrushType, - String? message, String? currentPageName, bool clearCurrentPageName = false, }) { @@ -87,7 +83,6 @@ class CanvasState { ? null : (selectedTextItemIndex ?? this.selectedTextItemIndex), isTrayShown: deselect ? false : (isTrayShown ?? this.isTrayShown), - message: message ?? this.message, currentPageName: clearCurrentPageName ? null : (currentPageName ?? this.currentPageName), @@ -112,7 +107,6 @@ class CanvasState { history == other.history && future == other.future && isTrayShown == other.isTrayShown && - message == other.message && currentPageName == other.currentPageName && currentDrawColor == other.currentDrawColor && currentStrokeWidth == other.currentStrokeWidth && @@ -132,6 +126,5 @@ class CanvasState { currentDrawColor.hashCode ^ currentStrokeWidth.hashCode ^ currentBrushType.hashCode ^ - message.hashCode ^ currentPageName.hashCode; } diff --git a/lib/ui/screens/canvas_screen.dart b/lib/ui/screens/canvas_screen.dart index 1279058f..1676b177 100644 --- a/lib/ui/screens/canvas_screen.dart +++ b/lib/ui/screens/canvas_screen.dart @@ -220,15 +220,7 @@ class CanvasScreen extends StatelessWidget { ), ], ), - body: BlocConsumer( - listener: (context, state) { - // Show snackbar when there's a message from save/load operations - if (state.message != null) { - CustomSnackbar.showInfo(state.message!); - // Clear the message after showing - context.read().clearMessage(); - } - }, + body: BlocBuilder( builder: (context, state) { return GestureDetector( onTap: () { From a35a07cd1d91a403b87efe7e69f2acca550d2620 Mon Sep 17 00:00:00 2001 From: Shaik Zainab Date: Tue, 30 Sep 2025 12:28:28 +0530 Subject: [PATCH 2/3] centralised snackbar to canvascubit to remove duplicate msgs --- lib/cubit/canvas_cubit.dart | 4 ++++ lib/ui/screens/canvas_screen.dart | 6 +----- lib/ui/screens/save_page_dialog.dart | 6 ------ lib/ui/screens/saved_pages.dart | 14 +++----------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/lib/cubit/canvas_cubit.dart b/lib/cubit/canvas_cubit.dart index 61761280..e76d2fcd 100644 --- a/lib/cubit/canvas_cubit.dart +++ b/lib/cubit/canvas_cubit.dart @@ -307,6 +307,7 @@ class CanvasCubit extends Cubit { history: newHistory, future: [state, ...state.future], )); + CustomSnackbar.showInfo('Action undone'); } } @@ -319,6 +320,7 @@ class CanvasCubit extends Cubit { future: newFuture, history: [...state.history, state], )); + CustomSnackbar.showInfo('Action redone'); } } @@ -342,6 +344,7 @@ class CanvasCubit extends Cubit { clearBackgroundImage: true, ), ); + CustomSnackbar.showInfo('Canvas cleared'); } void _updateState({ @@ -884,6 +887,7 @@ class CanvasCubit extends Cubit { history: newHistory, future: [], // Clear future as we've made a new action )); + CustomSnackbar.showInfo('Drawings cleared'); } // Undo the last drawing stroke diff --git a/lib/ui/screens/canvas_screen.dart b/lib/ui/screens/canvas_screen.dart index 1676b177..0e08d468 100644 --- a/lib/ui/screens/canvas_screen.dart +++ b/lib/ui/screens/canvas_screen.dart @@ -72,11 +72,10 @@ class CanvasScreen extends StatelessWidget { if (cubit.state.textItems.isNotEmpty || cubit.state.backgroundImagePath != null) { cubit.clearCanvas(); - CustomSnackbar.showInfo('Canvas cleared'); } else if (cubit.state.drawPaths.isNotEmpty) { cubit.clearDrawings(); - CustomSnackbar.showInfo('Drawings cleared'); } else { + // Show info when canvas is already empty CustomSnackbar.showInfo('Canvas is already empty'); } }, @@ -99,7 +98,6 @@ class CanvasScreen extends StatelessWidget { final cubit = context.read(); if (cubit.state.history.isNotEmpty) { cubit.undo(); - CustomSnackbar.showInfo('Action undone'); } else { CustomSnackbar.showInfo('Nothing to undo'); } @@ -113,7 +111,6 @@ class CanvasScreen extends StatelessWidget { final cubit = context.read(); if (cubit.state.future.isNotEmpty) { cubit.redo(); - CustomSnackbar.showInfo('Action redone'); } else { CustomSnackbar.showInfo('Nothing to redo'); } @@ -133,7 +130,6 @@ class CanvasScreen extends StatelessWidget { switch (value) { case 'new_page': cubit.createNewPage(); - CustomSnackbar.showInfo('New page created'); break; case 'load_pages': Navigator.push( diff --git a/lib/ui/screens/save_page_dialog.dart b/lib/ui/screens/save_page_dialog.dart index c2712141..07f936a6 100644 --- a/lib/ui/screens/save_page_dialog.dart +++ b/lib/ui/screens/save_page_dialog.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:texterra/utils/custom_snackbar.dart'; import '../../cubit/canvas_cubit.dart'; import '../../constants/color_constants.dart'; @@ -99,17 +98,12 @@ class _SavePageDialogState extends State { if (mounted) { Navigator.of(context).pop(); - - // Show success message - CustomSnackbar.showSuccess('Page "$pageName" saved successfully!'); } } catch (e) { if (mounted) { setState(() { _isSaving = false; }); - - CustomSnackbar.showError('Error saving page: $e'); } } } diff --git a/lib/ui/screens/saved_pages.dart b/lib/ui/screens/saved_pages.dart index 42bdbb7b..25d6966f 100644 --- a/lib/ui/screens/saved_pages.dart +++ b/lib/ui/screens/saved_pages.dart @@ -51,7 +51,7 @@ class _SavedPagesScreenState extends State { } catch (e) { // Handle error if (mounted) { - CustomSnackbar.showError('Error deleting page'); + CustomSnackbar.showError('Error loading pages'); } } finally { if (mounted) { @@ -295,9 +295,7 @@ class _SavedPagesScreenState extends State { Navigator.of(context).pop(); } } catch (e) { - if (mounted) { - CustomSnackbar.showError('Error deleting page'); - } + // Error is already handled by cubit } } @@ -358,14 +356,8 @@ class _SavedPagesScreenState extends State { try { await context.read().deletePage(pageName); await _loadSavedPages(); // Refresh the list - - if (mounted) { - CustomSnackbar.showSuccess('Page "$pageName" deleted successfully'); - } } catch (e) { - if (mounted) { - CustomSnackbar.showError('Error deleting page'); - } + // Error is already handled by cubit } } } From 2946a757398ab5ffe3ab0fe8187d2ba847f457a5 Mon Sep 17 00:00:00 2001 From: Shaik Zainab Date: Tue, 30 Sep 2025 14:54:14 +0530 Subject: [PATCH 3/3] removed undo/redo snackbar --- lib/cubit/canvas_cubit.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/cubit/canvas_cubit.dart b/lib/cubit/canvas_cubit.dart index e76d2fcd..0f02ba0c 100644 --- a/lib/cubit/canvas_cubit.dart +++ b/lib/cubit/canvas_cubit.dart @@ -307,7 +307,6 @@ class CanvasCubit extends Cubit { history: newHistory, future: [state, ...state.future], )); - CustomSnackbar.showInfo('Action undone'); } } @@ -320,7 +319,6 @@ class CanvasCubit extends Cubit { future: newFuture, history: [...state.history, state], )); - CustomSnackbar.showInfo('Action redone'); } }