diff --git a/b0esche_cloud/lib/pages/home_page.dart b/b0esche_cloud/lib/pages/home_page.dart index 0b5fb97..a11468a 100644 --- a/b0esche_cloud/lib/pages/home_page.dart +++ b/b0esche_cloud/lib/pages/home_page.dart @@ -85,7 +85,7 @@ class _HomePageState extends State with TickerProviderStateMixin { final controller = TextEditingController(); showDialog( context: context, - builder: (context) => Dialog( + builder: (dialogContext) => Dialog( backgroundColor: Colors.transparent, child: SizedBox( width: 400, @@ -96,121 +96,71 @@ class _HomePageState extends State with TickerProviderStateMixin { child: Container( padding: const EdgeInsets.all(24), decoration: AppTheme.glassDecoration, - child: BlocListener( - listener: (context, state) { - if (state is OrganizationLoaded && !state.isLoading) { - if (state.error == null) { - // Success - close dialog - Navigator.of(context).pop(); - } - } - }, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'Create New Organization', - style: TextStyle( - color: AppTheme.primaryText, - fontSize: 18, - fontWeight: FontWeight.bold, - ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Create New Organization', + style: TextStyle( + color: AppTheme.primaryText, + fontSize: 18, + fontWeight: FontWeight.bold, ), - const SizedBox(height: 16), - TextField( - cursorColor: AppTheme.accentColor, - controller: controller, - style: TextStyle(color: AppTheme.primaryText), - decoration: InputDecoration( - labelText: 'Organization Name', - labelStyle: TextStyle(color: AppTheme.secondaryText), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: AppTheme.accentColor.withValues(alpha: 0.5), - ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide(color: AppTheme.accentColor), + ), + const SizedBox(height: 16), + TextField( + cursorColor: AppTheme.accentColor, + controller: controller, + autofocus: true, + style: TextStyle(color: AppTheme.primaryText), + decoration: InputDecoration( + labelText: 'Organization Name', + labelStyle: TextStyle(color: AppTheme.secondaryText), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: AppTheme.accentColor.withValues(alpha: 0.5), ), ), - onSubmitted: (value) { - final name = controller.text.trim(); - if (name.isNotEmpty) { - BlocProvider.of( - context, - ).add(CreateOrganization(name)); - } - }, + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide(color: AppTheme.accentColor), + ), ), - const SizedBox(height: 24), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - ModernGlassButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text('Cancel'), - ), - const SizedBox(width: 16), - BlocBuilder( - builder: (context, state) { - final isLoading = state is OrganizationLoaded && - state.isLoading; - - if (isLoading) { - return Container( - padding: const EdgeInsets.symmetric( - horizontal: 24, - vertical: 14, - ), - child: const SizedBox( - width: 20, - height: 20, - child: CircularProgressIndicator( - strokeWidth: 2, - valueColor: AlwaysStoppedAnimation( - AppTheme.accentColor, - ), - ), - ), - ); - } - - return ModernGlassButton( - onPressed: () { - final name = controller.text.trim(); - if (name.isNotEmpty) { - BlocProvider.of( - context, - ).add(CreateOrganization(name)); - } - }, - child: const Text('Create'), - ); - }, - ), - ], - ), - const SizedBox(height: 8), - // Error message - BlocBuilder( - builder: (context, state) { - if (state is OrganizationLoaded && - state.error != null) { - return Text( - state.error!, - style: const TextStyle( - color: Colors.red, - fontSize: 12, - ), - ); - } - return const SizedBox.shrink(); - }, - ), - ], - ), + onSubmitted: (value) { + final name = controller.text.trim(); + if (name.isNotEmpty) { + // Use the parent context, not the dialog context + BlocProvider.of(context) + .add(CreateOrganization(name)); + Navigator.of(dialogContext).pop(); + } + }, + ), + const SizedBox(height: 24), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + ModernGlassButton( + onPressed: () => Navigator.of(dialogContext).pop(), + child: const Text('Cancel'), + ), + const SizedBox(width: 16), + ModernGlassButton( + onPressed: () { + final name = controller.text.trim(); + if (name.isNotEmpty) { + // Use the parent context, not the dialog context + BlocProvider.of(context) + .add(CreateOrganization(name)); + Navigator.of(dialogContext).pop(); + } + }, + child: const Text('Create'), + ), + ], + ), + ], ), ), ),