mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
86 lines
2.7 KiB
Dart
86 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/domain/models/person.model.dart';
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
|
import 'package:immich_mobile/generated/translations.g.dart';
|
|
import 'package:immich_mobile/providers/infrastructure/people.provider.dart';
|
|
import 'package:immich_mobile/utils/debug_print.dart';
|
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
|
|
|
class DriftPersonNameEditForm extends ConsumerStatefulWidget {
|
|
final DriftPerson person;
|
|
|
|
const DriftPersonNameEditForm({super.key, required this.person});
|
|
|
|
@override
|
|
ConsumerState<DriftPersonNameEditForm> createState() => _DriftPersonNameEditFormState();
|
|
}
|
|
|
|
class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonNameEditForm> {
|
|
late TextEditingController _formController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_formController = TextEditingController(text: widget.person.name);
|
|
}
|
|
|
|
Future<void> onEdit(String personId, String newName) async {
|
|
try {
|
|
final result = await ref.read(driftPeopleServiceProvider).updateName(personId, newName);
|
|
if (result != 0) {
|
|
ref.invalidate(driftGetAllPeopleProvider);
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
|
|
context.pop<String>(newName);
|
|
}
|
|
} catch (error) {
|
|
dPrint(() => 'Error updating name: $error');
|
|
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: context.t.scaffold_body_error_occurred,
|
|
gravity: ToastGravity.BOTTOM,
|
|
toastType: ToastType.error,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(context.t.edit_name, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
content: SingleChildScrollView(
|
|
child: TextFormField(
|
|
controller: _formController,
|
|
textCapitalization: TextCapitalization.words,
|
|
autofocus: true,
|
|
decoration: InputDecoration(hintText: context.t.name, border: const OutlineInputBorder()),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => context.pop(null),
|
|
child: Text(
|
|
context.t.cancel,
|
|
style: TextStyle(color: Colors.red[300], fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () => onEdit(widget.person.id, _formController.text),
|
|
child: Text(
|
|
context.t.save,
|
|
style: TextStyle(color: context.primaryColor, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|