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,121 +96,71 @@ 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>(
|
child: Column(
|
||||||
listener: (context, state) {
|
mainAxisSize: MainAxisSize.min,
|
||||||
if (state is OrganizationLoaded && !state.isLoading) {
|
children: [
|
||||||
if (state.error == null) {
|
Text(
|
||||||
// Success - close dialog
|
'Create New Organization',
|
||||||
Navigator.of(context).pop();
|
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(
|
const SizedBox(height: 16),
|
||||||
cursorColor: AppTheme.accentColor,
|
TextField(
|
||||||
controller: controller,
|
cursorColor: AppTheme.accentColor,
|
||||||
style: TextStyle(color: AppTheme.primaryText),
|
controller: controller,
|
||||||
decoration: InputDecoration(
|
autofocus: true,
|
||||||
labelText: 'Organization Name',
|
style: TextStyle(color: AppTheme.primaryText),
|
||||||
labelStyle: TextStyle(color: AppTheme.secondaryText),
|
decoration: InputDecoration(
|
||||||
enabledBorder: OutlineInputBorder(
|
labelText: 'Organization Name',
|
||||||
borderRadius: BorderRadius.circular(8),
|
labelStyle: TextStyle(color: AppTheme.secondaryText),
|
||||||
borderSide: BorderSide(
|
enabledBorder: OutlineInputBorder(
|
||||||
color: AppTheme.accentColor.withValues(alpha: 0.5),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
borderSide: BorderSide(
|
||||||
),
|
color: AppTheme.accentColor.withValues(alpha: 0.5),
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
borderSide: BorderSide(color: AppTheme.accentColor),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onSubmitted: (value) {
|
focusedBorder: OutlineInputBorder(
|
||||||
final name = controller.text.trim();
|
borderRadius: BorderRadius.circular(8),
|
||||||
if (name.isNotEmpty) {
|
borderSide: BorderSide(color: AppTheme.accentColor),
|
||||||
BlocProvider.of<OrganizationBloc>(
|
),
|
||||||
context,
|
|
||||||
).add(CreateOrganization(name));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
onSubmitted: (value) {
|
||||||
Row(
|
final name = controller.text.trim();
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
if (name.isNotEmpty) {
|
||||||
children: [
|
// Use the parent context, not the dialog context
|
||||||
ModernGlassButton(
|
BlocProvider.of<OrganizationBloc>(context)
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
.add(CreateOrganization(name));
|
||||||
child: const Text('Cancel'),
|
Navigator.of(dialogContext).pop();
|
||||||
),
|
}
|
||||||
const SizedBox(width: 16),
|
},
|
||||||
BlocBuilder<OrganizationBloc, OrganizationState>(
|
),
|
||||||
builder: (context, state) {
|
const SizedBox(height: 24),
|
||||||
final isLoading = state is OrganizationLoaded &&
|
Row(
|
||||||
state.isLoading;
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
if (isLoading) {
|
ModernGlassButton(
|
||||||
return Container(
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||||
padding: const EdgeInsets.symmetric(
|
child: const Text('Cancel'),
|
||||||
horizontal: 24,
|
),
|
||||||
vertical: 14,
|
const SizedBox(width: 16),
|
||||||
),
|
ModernGlassButton(
|
||||||
child: const SizedBox(
|
onPressed: () {
|
||||||
width: 20,
|
final name = controller.text.trim();
|
||||||
height: 20,
|
if (name.isNotEmpty) {
|
||||||
child: CircularProgressIndicator(
|
// Use the parent context, not the dialog context
|
||||||
strokeWidth: 2,
|
BlocProvider.of<OrganizationBloc>(context)
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(
|
.add(CreateOrganization(name));
|
||||||
AppTheme.accentColor,
|
Navigator.of(dialogContext).pop();
|
||||||
),
|
}
|
||||||
),
|
},
|
||||||
),
|
child: const Text('Create'),
|
||||||
);
|
),
|
||||||
}
|
],
|
||||||
|
),
|
||||||
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();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user