Fix org creation dialog - use parent context for BlocProvider access

This commit is contained in:
Leon Bösche
2026-01-11 02:50:14 +01:00
parent 1151abab28
commit 56526c8fc5

View File

@@ -85,7 +85,7 @@ class _HomePageState extends State<HomePage> 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<HomePage> with TickerProviderStateMixin {
child: Container(
padding: const EdgeInsets.all(24),
decoration: AppTheme.glassDecoration,
child: BlocListener<OrganizationBloc, OrganizationState>(
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<OrganizationBloc>(
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<OrganizationBloc, OrganizationState>(
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<Color>(
AppTheme.accentColor,
),
),
),
);
}
return ModernGlassButton(
onPressed: () {
final name = controller.text.trim();
if (name.isNotEmpty) {
BlocProvider.of<OrganizationBloc>(
context,
).add(CreateOrganization(name));
}
},
child: const Text('Create'),
);
},
),
],
),
const SizedBox(height: 8),
// Error message
BlocBuilder<OrganizationBloc, OrganizationState>(
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<OrganizationBloc>(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<OrganizationBloc>(context)
.add(CreateOrganization(name));
Navigator.of(dialogContext).pop();
}
},
child: const Text('Create'),
),
],
),
],
),
),
),