Skip to content

Commit 23b4a95

Browse files
committed
Reset pointer on app hide, see #280
1 parent 889cb74 commit 23b4a95

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

app/lib/cubits/current_index.dart

+2
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,6 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
362362
emit(state.copyWith(
363363
location: location ?? state.location, saved: saved ?? state.saved));
364364
}
365+
366+
void resetInput() {}
365367
}

app/lib/dialogs/introduction/start.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import 'package:butterfly/models/document.dart';
66
import 'package:butterfly/models/template.dart';
77
import 'package:flutter/material.dart';
88
import 'package:flutter_bloc/flutter_bloc.dart';
9-
import 'package:go_router/go_router.dart';
109
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
10+
import 'package:go_router/go_router.dart';
1111
import 'package:phosphor_flutter/phosphor_flutter.dart';
1212

1313
import '../../api/format_date_time.dart';
@@ -164,7 +164,6 @@ class _CreateStartViewState extends State<_CreateStartView> {
164164
createdAt: DateTime.now(),
165165
);
166166

167-
bloc.clearHistory();
168167
transformCubit.reset();
169168
currentIndexCubit.reset(document);
170169
bloc.emit(DocumentLoadSuccess(document,
@@ -175,6 +174,7 @@ class _CreateStartViewState extends State<_CreateStartView> {
175174
''),
176175
currentIndexCubit: currentIndexCubit,
177176
settingsCubit: settingsCubit));
177+
bloc.clearHistory();
178178
await bloc.load();
179179
});
180180
},

app/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import 'setup.dart' if (dart.library.html) 'setup_web.dart';
2626
import 'theme/manager.dart';
2727
import 'views/main.dart';
2828

29-
const kFileVersion = 6;
29+
const kFileVersion = 5;
3030
Future<void> main([List<String> args = const []]) async {
3131
WidgetsFlutterBinding.ensureInitialized();
3232

app/lib/views/view.dart

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class MainViewViewport extends StatefulWidget {
2121

2222
enum _MouseState { normal, inverse, scale }
2323

24-
class _MainViewViewportState extends State<MainViewViewport> {
24+
class _MainViewViewportState extends State<MainViewViewport>
25+
with WidgetsBindingObserver {
2526
double size = 1.0;
2627
GlobalKey paintKey = GlobalKey();
2728
_MouseState _mouseState = _MouseState.normal;
@@ -40,6 +41,15 @@ class _MainViewViewportState extends State<MainViewViewport> {
4041
super.dispose();
4142
}
4243

44+
@override
45+
void didChangeAppLifecycleState(AppLifecycleState state) {
46+
if (state == AppLifecycleState.resumed) {
47+
context.read<DocumentBloc>().refresh();
48+
} else {
49+
context.read<CurrentIndexCubit>().resetInput();
50+
}
51+
}
52+
4353
void _handleKey(RawKeyEvent event) {
4454
if (event.data.isShiftPressed) {
4555
_mouseState = _MouseState.inverse;

app/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dev_dependencies:
6868
freezed: ^2.1.0+1
6969
build_runner: ^2.2.0
7070
json_serializable: ^6.3.1
71-
espresso: ^0.2.0+3
71+
espresso: ^0.2.0+4
7272

7373
# For information on the generic Dart part of this file, see the
7474
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)