Merge pull request #674 from ente-io/attempt_to_button

Edit Description: Add done and cancel button
This commit is contained in:
Ashil 2022-11-29 07:47:49 +05:30 committed by GitHub
commit a3a026210f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 10 deletions

View file

@ -102,6 +102,9 @@ PODS:
- Flutter
- in_app_purchase_storekit (0.0.1):
- Flutter
- keyboard_visibility (0.5.0):
- Flutter
- Reachability
- libwebp (1.2.3):
- libwebp/demux (= 1.2.3)
- libwebp/mux (= 1.2.3)
@ -193,6 +196,7 @@ DEPENDENCIES:
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- image_editor (from `.symlinks/plugins/image_editor/ios`)
- in_app_purchase_storekit (from `.symlinks/plugins/in_app_purchase_storekit/ios`)
- keyboard_visibility (from `.symlinks/plugins/keyboard_visibility/ios`)
- local_auth (from `.symlinks/plugins/local_auth/ios`)
- media_extension (from `.symlinks/plugins/media_extension/ios`)
- motionphoto (from `.symlinks/plugins/motionphoto/ios`)
@ -271,6 +275,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/image_editor/ios"
in_app_purchase_storekit:
:path: ".symlinks/plugins/in_app_purchase_storekit/ios"
keyboard_visibility:
:path: ".symlinks/plugins/keyboard_visibility/ios"
local_auth:
:path: ".symlinks/plugins/local_auth/ios"
media_extension:
@ -336,6 +342,7 @@ SPEC CHECKSUMS:
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
image_editor: eab82a302a6623a866da5145b7c4c0ee8a4ffbb4
in_app_purchase_storekit: d7fcf4646136ec258e237872755da8ea6c1b6096
keyboard_visibility: 96a24de806fe6823c3ad956c01ba2ec6d056616f
libwebp: 60305b2e989864154bd9be3d772730f08fc6a59c
local_auth: 1740f55d7af0a2e2a8684ce225fe79d8931e808c
Mantle: c5aa8794a29a022dfbbfc9799af95f477a69b62d

View file

@ -287,6 +287,7 @@
"${BUILT_PRODUCTS_DIR}/fluttertoast/fluttertoast.framework",
"${BUILT_PRODUCTS_DIR}/image_editor/image_editor.framework",
"${BUILT_PRODUCTS_DIR}/in_app_purchase_storekit/in_app_purchase_storekit.framework",
"${BUILT_PRODUCTS_DIR}/keyboard_visibility/keyboard_visibility.framework",
"${BUILT_PRODUCTS_DIR}/libwebp/libwebp.framework",
"${BUILT_PRODUCTS_DIR}/local_auth/local_auth.framework",
"${BUILT_PRODUCTS_DIR}/media_extension/media_extension.framework",
@ -341,6 +342,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/fluttertoast.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_editor.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/in_app_purchase_storekit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/keyboard_visibility.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/local_auth.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/media_extension.framework",

View file

@ -0,0 +1,32 @@
import 'package:flutter/widgets.dart';
class KeyboardOverlay {
static OverlayEntry? _overlayEntry;
static showOverlay(BuildContext context, Widget child) {
if (_overlayEntry != null) {
return;
}
final OverlayState? overlayState = Overlay.of(context);
_overlayEntry = OverlayEntry(
builder: (context) {
return Positioned(
bottom: MediaQuery.of(context).viewInsets.bottom,
right: 0.0,
left: 0.0,
child: child,
);
},
);
overlayState!.insert(_overlayEntry!);
}
static removeOverlay() {
if (_overlayEntry != null) {
_overlayEntry!.remove();
_overlayEntry = null;
}
}
}

View file

@ -0,0 +1,52 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photos/theme/ente_theme.dart';
class KeyboardTopButton extends StatelessWidget {
final VoidCallback? onDoneTap;
final VoidCallback? onCancelTap;
final String doneText;
final String cancelText;
const KeyboardTopButton({
super.key,
this.doneText = "Done",
this.cancelText = "Cancel",
this.onDoneTap,
this.onCancelTap,
});
@override
Widget build(BuildContext context) {
final enteTheme = getEnteTextTheme(context);
final colorScheme = getEnteColorScheme(context);
return Container(
width: double.infinity,
decoration: BoxDecoration(
border: Border(
top: BorderSide(width: 1.0, color: colorScheme.strokeFaint),
bottom: BorderSide(width: 1.0, color: colorScheme.strokeFaint),
),
color: colorScheme.backgroundElevated2,
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CupertinoButton(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 14),
onPressed: onCancelTap,
child: Text(cancelText, style: enteTheme.bodyBold),
),
CupertinoButton(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 14),
onPressed: onDoneTap,
child: Text(doneText, style: enteTheme.bodyBold),
),
],
),
),
);
}
}

View file

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/models/file.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';
class FileCaptionWidget extends StatefulWidget {
@ -18,10 +20,12 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
// currentLength/maxLength will show up
static const int counterThreshold = 1000;
int currentLength = 0;
final _textController = TextEditingController();
final _focusNode = FocusNode();
String? editedCaption;
String hintText = fileCaptionDefaultHint;
Widget? keyboardTopButtoms;
@override
void initState() {
@ -49,15 +53,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
final textTheme = getEnteTextTheme(context);
return TextField(
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,
focusNode: _focusNode,
@ -94,7 +90,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
minLines: 1,
maxLines: 10,
textCapitalization: TextCapitalization.sentences,
keyboardType: TextInputType.text,
keyboardType: TextInputType.multiline,
onChanged: (value) {
setState(() {
hintText = fileCaptionDefaultHint;
@ -105,11 +101,46 @@ 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() {
_textController.text = widget.file.caption ?? '';
_focusNode.unfocus();
editedCaption = null;
}
void onDoneTap() {
_focusNode.unfocus();
_onDoneClick(context);
}
void _focusNodeListener() {
final caption = widget.file.caption;
if (_focusNode.hasFocus && caption != null) {
_textController.text = 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();
}
}
}

View file

@ -707,6 +707,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.7.0"
keyboard_visibility:
dependency: "direct main"
description:
name: keyboard_visibility
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.6"
like_button:
dependency: "direct main"
description:

View file

@ -72,6 +72,7 @@ dependencies:
implicitly_animated_reorderable_list: ^0.4.0
in_app_purchase: ^3.0.7
intl: ^0.17.0
keyboard_visibility: ^0.5.6
like_button: ^2.0.2
loading_animations: ^2.1.0
local_auth: ^1.1.5