Skip to content

Commit a5eedfd

Browse files
committed
fix: workaround for enabling keyboard stream after refocus
1 parent bec4440 commit a5eedfd

File tree

3 files changed

+114
-85
lines changed

3 files changed

+114
-85
lines changed

lib/pages/editor/editor.dart

Lines changed: 96 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart' show kDebugMode;
99
import 'package:flutter/material.dart';
1010
import 'package:flutter/services.dart';
1111
import 'package:flutter_quill/flutter_quill.dart' as flutter_quill;
12+
import 'package:focus_detector/focus_detector.dart';
1213
import 'package:keybinder/keybinder.dart';
1314
import 'package:logging/logging.dart';
1415
import 'package:printing/printing.dart';
@@ -1555,96 +1556,106 @@ class EditorState extends State<Editor> {
15551556
child: child!,
15561557
);
15571558
},
1558-
child: Scaffold(
1559-
appBar: DynamicMaterialApp.isFullscreen
1560-
? null
1561-
: AppBar(
1562-
toolbarHeight: kToolbarHeight,
1563-
title: widget.customTitle != null
1564-
? Text(widget.customTitle!)
1565-
: Form(
1566-
key: _filenameFormKey,
1567-
autovalidateMode: AutovalidateMode.onUserInteraction,
1568-
child: TextFormField(
1569-
decoration: const InputDecoration(
1570-
border: InputBorder.none,
1559+
child: FocusDetector(
1560+
onFocusGained: () {
1561+
// Key bindings won't work until keyboard is shown at least once for some reason.
1562+
// This is a workaround to fix that. It should be unnoticable to the user.
1563+
if (Platform.isAndroid) {
1564+
SystemChannels.textInput.invokeMethod('TextInput.show');
1565+
SystemChannels.textInput.invokeMethod('TextInput.hide');
1566+
}
1567+
},
1568+
child: Scaffold(
1569+
appBar: DynamicMaterialApp.isFullscreen
1570+
? null
1571+
: AppBar(
1572+
toolbarHeight: kToolbarHeight,
1573+
title: widget.customTitle != null
1574+
? Text(widget.customTitle!)
1575+
: Form(
1576+
key: _filenameFormKey,
1577+
autovalidateMode: AutovalidateMode.onUserInteraction,
1578+
child: TextFormField(
1579+
decoration: const InputDecoration(
1580+
border: InputBorder.none,
1581+
),
1582+
controller: filenameTextEditingController,
1583+
onChanged: renameFile,
1584+
autofocus: needsNaming,
1585+
validator: _validateFilenameTextField,
15711586
),
1572-
controller: filenameTextEditingController,
1573-
onChanged: renameFile,
1574-
autofocus: needsNaming,
1575-
validator: _validateFilenameTextField,
15761587
),
1577-
),
1578-
leading: SaveIndicator(
1579-
savingState: savingState,
1580-
triggerSave: saveToFile,
1581-
),
1582-
actions: [
1583-
IconButton(
1584-
icon: const AdaptiveIcon(
1585-
icon: Icons.insert_page_break,
1586-
cupertinoIcon: CupertinoIcons.add,
1587-
),
1588-
tooltip: t.editor.menu.insertPage,
1589-
onPressed: () => setState(() {
1590-
final currentPageIndex = this.currentPageIndex;
1591-
insertPageAfter(currentPageIndex);
1592-
CanvasGestureDetector.scrollToPage(
1593-
pageIndex: currentPageIndex + 1,
1594-
pages: coreInfo.pages,
1595-
screenWidth: MediaQuery.sizeOf(context).width,
1596-
transformationController: _transformationController,
1597-
);
1598-
}),
1588+
leading: SaveIndicator(
1589+
savingState: savingState,
1590+
triggerSave: saveToFile,
15991591
),
1600-
IconButton(
1601-
icon: const AdaptiveIcon(
1602-
icon: Icons.grid_view,
1603-
cupertinoIcon: CupertinoIcons.rectangle_grid_2x2,
1592+
actions: [
1593+
IconButton(
1594+
icon: const AdaptiveIcon(
1595+
icon: Icons.insert_page_break,
1596+
cupertinoIcon: CupertinoIcons.add,
1597+
),
1598+
tooltip: t.editor.menu.insertPage,
1599+
onPressed: () => setState(() {
1600+
final currentPageIndex = this.currentPageIndex;
1601+
insertPageAfter(currentPageIndex);
1602+
CanvasGestureDetector.scrollToPage(
1603+
pageIndex: currentPageIndex + 1,
1604+
pages: coreInfo.pages,
1605+
screenWidth: MediaQuery.sizeOf(context).width,
1606+
transformationController: _transformationController,
1607+
);
1608+
}),
16041609
),
1605-
tooltip: t.editor.pages,
1606-
onPressed: () {
1607-
showDialog(
1608-
context: context,
1609-
builder: (context) => AdaptiveAlertDialog(
1610-
title: Text(t.editor.pages),
1611-
content: pageManager(context),
1612-
actions: const [],
1613-
),
1614-
);
1615-
},
1616-
),
1617-
IconButton(
1618-
icon: const AdaptiveIcon(
1619-
icon: Icons.more_vert,
1620-
cupertinoIcon: CupertinoIcons.ellipsis_vertical,
1610+
IconButton(
1611+
icon: const AdaptiveIcon(
1612+
icon: Icons.grid_view,
1613+
cupertinoIcon: CupertinoIcons.rectangle_grid_2x2,
1614+
),
1615+
tooltip: t.editor.pages,
1616+
onPressed: () {
1617+
showDialog(
1618+
context: context,
1619+
builder: (context) => AdaptiveAlertDialog(
1620+
title: Text(t.editor.pages),
1621+
content: pageManager(context),
1622+
actions: const [],
1623+
),
1624+
);
1625+
},
16211626
),
1622-
onPressed: () {
1623-
showModalBottomSheet(
1624-
context: context,
1625-
builder: (context) => bottomSheet(context),
1626-
isScrollControlled: true,
1627-
showDragHandle: true,
1628-
backgroundColor: colorScheme.surface,
1629-
constraints: const BoxConstraints(
1630-
maxWidth: 500,
1631-
),
1632-
);
1633-
},
1634-
)
1635-
],
1636-
),
1637-
body: body,
1638-
floatingActionButton: (DynamicMaterialApp.isFullscreen &&
1639-
!Prefs.editorToolbarShowInFullscreen.value)
1640-
? FloatingActionButton(
1641-
shape: cupertino ? const CircleBorder() : null,
1642-
onPressed: () {
1643-
DynamicMaterialApp.setFullscreen(false, updateSystem: true);
1644-
},
1645-
child: const Icon(Icons.fullscreen_exit),
1646-
)
1647-
: null,
1627+
IconButton(
1628+
icon: const AdaptiveIcon(
1629+
icon: Icons.more_vert,
1630+
cupertinoIcon: CupertinoIcons.ellipsis_vertical,
1631+
),
1632+
onPressed: () {
1633+
showModalBottomSheet(
1634+
context: context,
1635+
builder: (context) => bottomSheet(context),
1636+
isScrollControlled: true,
1637+
showDragHandle: true,
1638+
backgroundColor: colorScheme.surface,
1639+
constraints: const BoxConstraints(
1640+
maxWidth: 500,
1641+
),
1642+
);
1643+
},
1644+
)
1645+
],
1646+
),
1647+
body: body,
1648+
floatingActionButton: (DynamicMaterialApp.isFullscreen &&
1649+
!Prefs.editorToolbarShowInFullscreen.value)
1650+
? FloatingActionButton(
1651+
shape: cupertino ? const CircleBorder() : null,
1652+
onPressed: () {
1653+
DynamicMaterialApp.setFullscreen(false, updateSystem: true);
1654+
},
1655+
child: const Icon(Icons.fullscreen_exit),
1656+
)
1657+
: null,
1658+
),
16481659
),
16491660
);
16501661
}

pubspec.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,14 @@ packages:
531531
description: flutter
532532
source: sdk
533533
version: "0.0.0"
534+
focus_detector:
535+
dependency: "direct main"
536+
description:
537+
name: focus_detector
538+
sha256: "05e32d9dd378cd54f1a3f9ce813c05156f28eb83f8e68f5bf1a37e9cdb21af1c"
539+
url: "https://pub.dev"
540+
source: hosted
541+
version: "2.0.1"
534542
font_awesome_flutter:
535543
dependency: "direct main"
536544
description:
@@ -1431,6 +1439,14 @@ packages:
14311439
url: "https://pub.dev"
14321440
source: hosted
14331441
version: "3.0.2"
1442+
visibility_detector:
1443+
dependency: transitive
1444+
description:
1445+
name: visibility_detector
1446+
sha256: ec932527913f32f65aa01d3a393504240b9e9021ecc77123f017755605e48832
1447+
url: "https://pub.dev"
1448+
source: hosted
1449+
version: "0.2.2"
14341450
vm_service:
14351451
dependency: transitive
14361452
description:

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ dependencies:
138138

139139
one_dollar_unistroke_recognizer: ^1.0.0
140140

141+
focus_detector: ^2.0.1
142+
141143
meta: ^1.0.0
142144

143145
mutex: ^3.1.0

0 commit comments

Comments
 (0)