2022-04-28 21:46:37 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/sharing/models/shared_album.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/sharing/providers/album_viewer.provider.dart';
|
|
|
|
|
|
|
|
class AlbumViewerEditableTitle extends HookConsumerWidget {
|
|
|
|
final SharedAlbum albumInfo;
|
|
|
|
final FocusNode titleFocusNode;
|
2022-06-25 13:12:47 -07:00
|
|
|
const AlbumViewerEditableTitle(
|
|
|
|
{Key? key, required this.albumInfo, required this.titleFocusNode})
|
|
|
|
: super(key: key);
|
2022-04-28 21:46:37 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-25 13:12:47 -07:00
|
|
|
final titleTextEditController =
|
|
|
|
useTextEditingController(text: albumInfo.albumName);
|
2022-04-28 21:46:37 -07:00
|
|
|
|
|
|
|
void onFocusModeChange() {
|
|
|
|
if (!titleFocusNode.hasFocus && titleTextEditController.text.isEmpty) {
|
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText("Untitled");
|
|
|
|
titleTextEditController.text = "Untitled";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() {
|
|
|
|
titleFocusNode.addListener(onFocusModeChange);
|
|
|
|
return () {
|
|
|
|
titleFocusNode.removeListener(onFocusModeChange);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return TextField(
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value.isEmpty) {
|
|
|
|
} else {
|
|
|
|
ref.watch(albumViewerProvider.notifier).setEditTitleText(value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
focusNode: titleFocusNode,
|
|
|
|
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
|
|
|
controller: titleTextEditController,
|
|
|
|
onTap: () {
|
|
|
|
FocusScope.of(context).requestFocus(titleFocusNode);
|
|
|
|
|
2022-06-25 13:12:47 -07:00
|
|
|
ref
|
|
|
|
.watch(albumViewerProvider.notifier)
|
|
|
|
.setEditTitleText(albumInfo.albumName);
|
2022-04-28 21:46:37 -07:00
|
|
|
ref.watch(albumViewerProvider.notifier).enableEditAlbum();
|
|
|
|
|
|
|
|
if (titleTextEditController.text == 'Untitled') {
|
|
|
|
titleTextEditController.clear();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
|
|
|
suffixIcon: titleFocusNode.hasFocus
|
|
|
|
? IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
titleTextEditController.clear();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.cancel_rounded),
|
|
|
|
splashRadius: 10,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide: const BorderSide(color: Colors.transparent),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide: const BorderSide(color: Colors.transparent),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
focusColor: Colors.grey[300],
|
|
|
|
fillColor: Colors.grey[200],
|
|
|
|
filled: titleFocusNode.hasFocus,
|
|
|
|
hintText: 'Add a title',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|