Fix org creation dialog - use parent context for BlocProvider access
This commit is contained in:
@@ -85,7 +85,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => Dialog(
|
builder: (dialogContext) => Dialog(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 400,
|
width: 400,
|
||||||
@@ -96,15 +96,6 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
decoration: AppTheme.glassDecoration,
|
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(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -120,6 +111,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
TextField(
|
TextField(
|
||||||
cursorColor: AppTheme.accentColor,
|
cursorColor: AppTheme.accentColor,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
autofocus: true,
|
||||||
style: TextStyle(color: AppTheme.primaryText),
|
style: TextStyle(color: AppTheme.primaryText),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Organization Name',
|
labelText: 'Organization Name',
|
||||||
@@ -138,9 +130,10 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
onSubmitted: (value) {
|
onSubmitted: (value) {
|
||||||
final name = controller.text.trim();
|
final name = controller.text.trim();
|
||||||
if (name.isNotEmpty) {
|
if (name.isNotEmpty) {
|
||||||
BlocProvider.of<OrganizationBloc>(
|
// Use the parent context, not the dialog context
|
||||||
context,
|
BlocProvider.of<OrganizationBloc>(context)
|
||||||
).add(CreateOrganization(name));
|
.add(CreateOrganization(name));
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -149,66 +142,24 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
ModernGlassButton(
|
ModernGlassButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
BlocBuilder<OrganizationBloc, OrganizationState>(
|
ModernGlassButton(
|
||||||
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: () {
|
onPressed: () {
|
||||||
final name = controller.text.trim();
|
final name = controller.text.trim();
|
||||||
if (name.isNotEmpty) {
|
if (name.isNotEmpty) {
|
||||||
BlocProvider.of<OrganizationBloc>(
|
// Use the parent context, not the dialog context
|
||||||
context,
|
BlocProvider.of<OrganizationBloc>(context)
|
||||||
).add(CreateOrganization(name));
|
.add(CreateOrganization(name));
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Create'),
|
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();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -216,7 +167,6 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user