|
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
|
import 'package:photos/core/constants.dart';
|
|
import 'package:photos/core/constants.dart';
|
|
import 'package:photos/models/file.dart';
|
|
import 'package:photos/models/file.dart';
|
|
import 'package:photos/theme/ente_theme.dart';
|
|
import 'package:photos/theme/ente_theme.dart';
|
|
|
|
+import 'package:photos/ui/components/keyboard/keybiard_oveylay.dart';
|
|
|
|
+import 'package:photos/ui/components/keyboard/keyboard_top_button.dart';
|
|
import 'package:photos/utils/magic_util.dart';
|
|
import 'package:photos/utils/magic_util.dart';
|
|
|
|
|
|
class FileCaptionWidget extends StatefulWidget {
|
|
class FileCaptionWidget extends StatefulWidget {
|
|
@@ -18,10 +20,12 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
|
|
// currentLength/maxLength will show up
|
|
// currentLength/maxLength will show up
|
|
static const int counterThreshold = 1000;
|
|
static const int counterThreshold = 1000;
|
|
int currentLength = 0;
|
|
int currentLength = 0;
|
|
|
|
+
|
|
final _textController = TextEditingController();
|
|
final _textController = TextEditingController();
|
|
final _focusNode = FocusNode();
|
|
final _focusNode = FocusNode();
|
|
String? editedCaption;
|
|
String? editedCaption;
|
|
String hintText = fileCaptionDefaultHint;
|
|
String hintText = fileCaptionDefaultHint;
|
|
|
|
+ Widget? keyboardTopButtoms;
|
|
|
|
|
|
@override
|
|
@override
|
|
void initState() {
|
|
void initState() {
|
|
@@ -49,15 +53,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
|
|
final textTheme = getEnteTextTheme(context);
|
|
final textTheme = getEnteTextTheme(context);
|
|
return TextField(
|
|
return TextField(
|
|
onSubmitted: (value) async {
|
|
onSubmitted: (value) async {
|
|
- if (editedCaption != null) {
|
|
|
|
- final isSuccesful =
|
|
|
|
- await editFileCaption(context, widget.file, editedCaption);
|
|
|
|
- if (isSuccesful) {
|
|
|
|
- if (mounted) {
|
|
|
|
- Navigator.pop(context);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ await _onDoneClick(context);
|
|
},
|
|
},
|
|
controller: _textController,
|
|
controller: _textController,
|
|
focusNode: _focusNode,
|
|
focusNode: _focusNode,
|
|
@@ -94,7 +90,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
|
|
minLines: 1,
|
|
minLines: 1,
|
|
maxLines: 10,
|
|
maxLines: 10,
|
|
textCapitalization: TextCapitalization.sentences,
|
|
textCapitalization: TextCapitalization.sentences,
|
|
- keyboardType: TextInputType.text,
|
|
|
|
|
|
+ keyboardType: TextInputType.multiline,
|
|
onChanged: (value) {
|
|
onChanged: (value) {
|
|
setState(() {
|
|
setState(() {
|
|
hintText = fileCaptionDefaultHint;
|
|
hintText = fileCaptionDefaultHint;
|
|
@@ -105,11 +101,48 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Future<void> _onDoneClick(BuildContext context) async {
|
|
|
|
+ if (editedCaption != null) {
|
|
|
|
+ final isSuccesful =
|
|
|
|
+ await editFileCaption(context, widget.file, editedCaption);
|
|
|
|
+ if (isSuccesful) {
|
|
|
|
+ if (mounted) {
|
|
|
|
+ Navigator.pop(context);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void onCancelTap() {
|
|
|
|
+ _focusNode.unfocus();
|
|
|
|
+ if (widget.file.caption != null) {
|
|
|
|
+ _textController.text = widget.file.caption!;
|
|
|
|
+ }
|
|
|
|
+ editedCaption = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void onDoneTap() {
|
|
|
|
+ _focusNode.unfocus();
|
|
|
|
+ _onDoneClick(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
void _focusNodeListener() {
|
|
void _focusNodeListener() {
|
|
final caption = widget.file.caption;
|
|
final caption = widget.file.caption;
|
|
if (_focusNode.hasFocus && caption != null) {
|
|
if (_focusNode.hasFocus && caption != null) {
|
|
_textController.text = caption;
|
|
_textController.text = caption;
|
|
editedCaption = caption;
|
|
editedCaption = caption;
|
|
}
|
|
}
|
|
|
|
+ final bool hasFocus = _focusNode.hasFocus;
|
|
|
|
+ keyboardTopButtoms ??= KeyboardTopButton(
|
|
|
|
+ onDoneTap: onDoneTap,
|
|
|
|
+ onCancelTap: onCancelTap,
|
|
|
|
+ );
|
|
|
|
+ if (hasFocus) {
|
|
|
|
+ KeyboardOverlay.showOverlay(context, keyboardTopButtoms!);
|
|
|
|
+ } else {
|
|
|
|
+ debugPrint("Removing listener");
|
|
|
|
+
|
|
|
|
+ KeyboardOverlay.removeOverlay();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|