@@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
55import '../../core/database/app_database.dart' ;
66import '../../core/providers/app_providers.dart' ;
77import '../../shared/utils/formatting.dart' ;
8+ import '../../shared/widgets/confirm_dialog.dart' ;
89import '../../shared/widgets/student_avatar.dart' ;
910import '../avatar/avatar_editor_sheet.dart' ;
1011import 'student_draft.dart' ;
@@ -18,6 +19,7 @@ Future<StudentFormResult?> showStudentFormSheet({
1819 String ? initialOriginNote,
1920 String ? initialAvatarJson,
2021 String ? title,
22+ Future <void > Function ()? onDelete,
2123}) {
2224 return showModalBottomSheet <StudentFormResult >(
2325 context: context,
@@ -30,6 +32,7 @@ Future<StudentFormResult?> showStudentFormSheet({
3032 initialOriginNote: initialOriginNote,
3133 initialAvatarJson: initialAvatarJson,
3234 title: title,
35+ onDelete: onDelete,
3336 ),
3437 );
3538}
@@ -41,13 +44,15 @@ class _StudentFormSheet extends ConsumerStatefulWidget {
4144 this .initialOriginNote,
4245 this .initialAvatarJson,
4346 this .title,
47+ this .onDelete,
4448 });
4549
4650 final String ? initialFirstName;
4751 final String ? initialLastName;
4852 final String ? initialOriginNote;
4953 final String ? initialAvatarJson;
5054 final String ? title;
55+ final Future <void > Function ()? onDelete;
5156
5257 @override
5358 ConsumerState <_StudentFormSheet > createState () => _StudentFormSheetState ();
@@ -165,8 +170,18 @@ class _StudentFormSheetState extends ConsumerState<_StudentFormSheet> {
165170 ),
166171 const SizedBox (height: 24 ),
167172 Row (
168- mainAxisAlignment: MainAxisAlignment .end,
169173 children: [
174+ if (widget.onDelete != null ) ...[
175+ TextButton (
176+ onPressed: _delete,
177+ style: TextButton .styleFrom (
178+ foregroundColor:
179+ Theme .of (context).colorScheme.error,
180+ ),
181+ child: Text ('delete' .tr ()),
182+ ),
183+ ],
184+ const Spacer (),
170185 TextButton (
171186 onPressed: () => Navigator .of (context).pop (),
172187 child: Text ('cancel' .tr ()),
@@ -222,4 +237,27 @@ class _StudentFormSheetState extends ConsumerState<_StudentFormSheet> {
222237 avatarJson: _avatarJson,
223238 ));
224239 }
240+
241+ Future <void > _delete () async {
242+ final confirmed = await showConfirmDialog (
243+ context: context,
244+ title: 'confirm_delete' .tr (
245+ namedArgs: {
246+ 'name' : studentDisplayName (
247+ firstName: _firstNameController.text.trim (),
248+ lastName: _lastNameController.text.trim (),
249+ ),
250+ },
251+ ),
252+ body: 'confirm_delete_student_body' .tr (),
253+ );
254+ if (! confirmed || ! mounted) {
255+ return ;
256+ }
257+ await widget.onDelete !();
258+ if (! mounted) {
259+ return ;
260+ }
261+ Navigator .of (context).pop ();
262+ }
225263}
0 commit comments