Fix quick-capture dialog controller disposal race
This commit is contained in:
@@ -1323,39 +1323,12 @@ class _PersonInsightsPage extends ConsumerWidget {
|
||||
required String title,
|
||||
required String hintText,
|
||||
}) async {
|
||||
final TextEditingController controller = TextEditingController();
|
||||
final String? result = await showDialog<String>(
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
decoration: InputDecoration(hintText: hintText),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
final String value = controller.text.trim();
|
||||
if (value.isEmpty) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop(value);
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
);
|
||||
return _InsightQuickTextCaptureDialog(title: title, hintText: hintText);
|
||||
},
|
||||
);
|
||||
controller.dispose();
|
||||
return result;
|
||||
}
|
||||
|
||||
Widget _insightAvatar({
|
||||
@@ -1881,6 +1854,80 @@ class _InsightQuickReminderDialogState
|
||||
}
|
||||
}
|
||||
|
||||
class _InsightQuickTextCaptureDialog extends StatefulWidget {
|
||||
const _InsightQuickTextCaptureDialog({
|
||||
required this.title,
|
||||
required this.hintText,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String hintText;
|
||||
|
||||
@override
|
||||
State<_InsightQuickTextCaptureDialog> createState() =>
|
||||
_InsightQuickTextCaptureDialogState();
|
||||
}
|
||||
|
||||
class _InsightQuickTextCaptureDialogState
|
||||
extends State<_InsightQuickTextCaptureDialog> {
|
||||
late final TextEditingController _controller;
|
||||
bool _attemptedSubmit = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String value = _controller.text.trim();
|
||||
return AlertDialog(
|
||||
title: Text(widget.title),
|
||||
content: TextField(
|
||||
controller: _controller,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
autofocus: true,
|
||||
onChanged: (_) {
|
||||
if (_attemptedSubmit) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.hintText,
|
||||
errorText: _attemptedSubmit && value.isEmpty ? 'Required' : null,
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
final String submitted = _controller.text.trim();
|
||||
if (submitted.isEmpty) {
|
||||
setState(() {
|
||||
_attemptedSubmit = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop(submitted);
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InsightSectionCard extends StatelessWidget {
|
||||
const _InsightSectionCard({
|
||||
required this.title,
|
||||
|
||||
Reference in New Issue
Block a user