Skip to content

Commit 18bb358

Browse files
authored
fix: replace flutter_keyboard_visibility with flutter_keyboard_visibility_temp_fork to support Flutter/Wasm target (singerdmx#2293)
* fix: replace flutter_keyboard_visibility with flutter_keyboard_visibility_temp_fork to support wasm and be able to target the latest version of compileSdkVersion on Android * fix(example): remove hydrated_bloc to run Flutter/Wasm * fix(wasm): avoid using quill_controller_web_stub.dart for web which will throw exception due to usage of dart.library.html in a conditional check * chore: remove web package as no longer used * chore: add related comments to quill_controller_web_real.dart and quill_controller_web_stub.dart * chore: format quill_controller_web_real.dart and quill_controller_web_stub.dart
1 parent a8f4a18 commit 18bb358

File tree

8 files changed

+59
-85
lines changed

8 files changed

+59
-85
lines changed

example/lib/main.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flutter/foundation.dart' show kIsWeb;
21
import 'package:flutter/material.dart';
32
import 'package:flutter_bloc/flutter_bloc.dart';
43
import 'package:flutter_localizations/flutter_localizations.dart'
@@ -9,10 +8,6 @@ import 'package:flutter_localizations/flutter_localizations.dart'
98
import 'package:flutter_quill/flutter_quill.dart' show Document;
109
import 'package:flutter_quill/translations.dart' show FlutterQuillLocalizations;
1110
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
12-
import 'package:hydrated_bloc/hydrated_bloc.dart'
13-
show HydratedBloc, HydratedStorage;
14-
import 'package:path_provider/path_provider.dart'
15-
show getApplicationDocumentsDirectory;
1611

1712
import 'screens/home/widgets/home_screen.dart';
1813
import 'screens/quill/quill_screen.dart';
@@ -25,11 +20,6 @@ import 'screens/settings/widgets/settings_screen.dart';
2520

2621
void main() async {
2722
WidgetsFlutterBinding.ensureInitialized();
28-
HydratedBloc.storage = await HydratedStorage.build(
29-
storageDirectory: kIsWeb
30-
? HydratedStorage.webStorageDirectory
31-
: await getApplicationDocumentsDirectory(),
32-
);
3323
// ignore: deprecated_member_use
3424
FlutterQuillExtensions.useSuperClipboardPlugin();
3525
runApp(const MyApp());
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
import 'package:flutter/material.dart' show ThemeMode;
2+
import 'package:flutter_bloc/flutter_bloc.dart';
23
import 'package:freezed_annotation/freezed_annotation.dart';
3-
import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedCubit;
44

55
part 'settings_state.dart';
66
part 'settings_cubit.freezed.dart';
77
part 'settings_cubit.g.dart';
88

9-
class SettingsCubit extends HydratedCubit<SettingsState> {
9+
class SettingsCubit extends Cubit<SettingsState> {
1010
SettingsCubit() : super(const SettingsState());
1111

1212
void updateSettings(SettingsState newSettingsState) {
1313
emit(newSettingsState);
1414
}
15-
16-
@override
17-
SettingsState? fromJson(Map<String, dynamic> json) {
18-
return SettingsState.fromJson(json);
19-
}
20-
21-
@override
22-
Map<String, dynamic>? toJson(SettingsState state) {
23-
return state.toJson();
24-
}
2515
}

example/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies:
2727
# Bloc libraries
2828
bloc: ^8.1.4
2929
flutter_bloc: ^8.1.5
30-
hydrated_bloc: ^9.1.5
3130

3231
# Freezed
3332
freezed_annotation: ^2.4.1

lib/src/controller/quill_controller.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:math' as math;
22

3-
import 'package:flutter/foundation.dart' show kIsWeb;
43
import 'package:flutter/services.dart' show ClipboardData, Clipboard;
54
import 'package:flutter/widgets.dart';
65
import 'package:meta/meta.dart' show experimental;
@@ -21,9 +20,6 @@ import '../toolbar/config/simple_toolbar_configurations.dart';
2120
import 'quill_controller_configurations.dart';
2221
import 'quill_controller_rich_paste.dart';
2322

24-
import 'web/quill_controller_web_stub.dart'
25-
if (dart.library.html) 'web/quill_controller_web_real.dart';
26-
2723
typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
2824
typedef DeleteCallback = void Function(int cursorPosition, bool forward);
2925

@@ -40,11 +36,7 @@ class QuillController extends ChangeNotifier {
4036
this.readOnly = false,
4137
this.editorFocusNode,
4238
}) : _document = document,
43-
_selection = selection {
44-
if (kIsWeb) {
45-
initializeWebPasteEvent();
46-
}
47-
}
39+
_selection = selection;
4840

4941
factory QuillController.basic(
5042
{QuillControllerConfigurations configurations =
@@ -476,9 +468,6 @@ class QuillController extends ChangeNotifier {
476468
}
477469

478470
_isDisposed = true;
479-
if (kIsWeb) {
480-
cancelWebPasteEvent();
481-
}
482471
super.dispose();
483472
}
484473

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1+
// TODO: This might be removed from here or moved to quill_native_bridge
2+
// commented in https://github.com/singerdmx/flutter-quill/pull/2293
3+
// removed due to bug https://github.com/singerdmx/flutter-quill/issues/2220
4+
// added to solve https://github.com/singerdmx/flutter-quill/issues/1998#issuecomment-2361599854
5+
16
// This file should not be exported as the APIs in it are meant for internal usage only
27

3-
import 'dart:async' show StreamSubscription;
8+
// import 'dart:async' show StreamSubscription;
49

5-
import 'package:web/web.dart';
10+
// import 'package:web/web.dart';
611

7-
import '../quill_controller.dart';
8-
// ignore: unused_import
9-
import '../quill_controller_rich_paste.dart';
12+
// import '../quill_controller.dart';
13+
// // ignore: unused_import
14+
// import '../quill_controller_rich_paste.dart';
1015

11-
/// Paste event for the web.
12-
///
13-
/// Will be `null` when [QuillControllerWeb.initializeWebPasteEvent] was not called
14-
/// or the subscription was canceled due to calling [QuillControllerWeb.cancelWebPasteEvent]
15-
///
16-
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
17-
StreamSubscription? _webPasteEventSubscription;
16+
// /// Paste event for the web.
17+
// ///
18+
// /// Will be `null` when [QuillControllerWeb.initializeWebPasteEvent] was not called
19+
// /// or the subscription was canceled due to calling [QuillControllerWeb.cancelWebPasteEvent]
20+
// ///
21+
// /// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
22+
// StreamSubscription? _webPasteEventSubscription;
1823

19-
extension QuillControllerWeb on QuillController {
20-
void initializeWebPasteEvent() {
21-
_webPasteEventSubscription =
22-
EventStreamProviders.pasteEvent.forTarget(window.document).listen((e) {
23-
// TODO: See if we can support markdown paste
24-
final html = e.clipboardData?.getData('text/html');
25-
if (html == null) {
26-
return;
27-
}
28-
// TODO: Temporarily disable the rich text pasting feature as a workaround
29-
// due to issue https://github.com/singerdmx/flutter-quill/issues/2220
30-
// pasteHTML(html: html);
31-
});
32-
}
24+
// extension QuillControllerWeb on QuillController {
25+
// void initializeWebPasteEvent() {
26+
// _webPasteEventSubscription =
27+
// EventStreamProviders.pasteEvent.forTarget(window.document).listen((e) {
28+
// final html = e.clipboardData?.getData('text/html');
29+
// if (html == null) {
30+
// return;
31+
// }
32+
// // TODO: Temporarily disable the rich text pasting feature as a workaround
33+
// // due to issue https://github.com/singerdmx/flutter-quill/issues/2220
34+
// // pasteHTML(html: html);
35+
// });
36+
// }
3337

34-
void cancelWebPasteEvent() {
35-
_webPasteEventSubscription?.cancel();
36-
_webPasteEventSubscription = null;
37-
}
38-
}
38+
// void cancelWebPasteEvent() {
39+
// _webPasteEventSubscription?.cancel();
40+
// _webPasteEventSubscription = null;
41+
// }
42+
// }
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
// This file should not be exported as the APIs in it are meant for internal usage only
1+
// See quill_controller_web_real.dart if you want to know why this is not removed yet
2+
// will be addressed in future releases.
23

3-
import '../quill_controller.dart';
4+
// // This file should not be exported as the APIs in it are meant for internal usage only
45

5-
// This is a mock implementation to compile the app on non-web platforms.
6-
// The real implementation is quill_controller_web_real.dart
6+
// import '../quill_controller.dart';
77

8-
extension QuillControllerWeb on QuillController {
9-
void initializeWebPasteEvent() {
10-
throw UnsupportedError(
11-
'The initializeWebPasteEvent() method should be called only on web.',
12-
);
13-
}
8+
// // This is a mock implementation to compile the app on non-web platforms.
9+
// // The real implementation is quill_controller_web_real.dart
1410

15-
void cancelWebPasteEvent() {
16-
throw UnsupportedError(
17-
'The closeWebPasteEvent() method should be called only on web.',
18-
);
19-
}
20-
}
11+
// extension QuillControllerWeb on QuillController {
12+
// void initializeWebPasteEvent() {
13+
// throw UnsupportedError(
14+
// 'The initializeWebPasteEvent() method should be called only on web.',
15+
// );
16+
// }
17+
18+
// void cancelWebPasteEvent() {
19+
// throw UnsupportedError(
20+
// 'The closeWebPasteEvent() method should be called only on web.',
21+
// );
22+
// }
23+
// }

lib/src/editor/raw_editor/raw_editor_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:flutter/rendering.dart' show RenderAbstractViewport;
1010
import 'package:flutter/scheduler.dart' show SchedulerBinding;
1111
import 'package:flutter/services.dart'
1212
show Clipboard, HardwareKeyboard, SystemChannels, TextInputControl;
13-
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'
13+
import 'package:flutter_keyboard_visibility_temp_fork/flutter_keyboard_visibility_temp_fork.dart'
1414
show KeyboardVisibilityController;
1515

1616
import '../../common/structs/horizontal_spacing.dart';

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ dependencies:
5050
equatable: ^2.0.5
5151
meta: ^1.10.0
5252
html: ^0.15.4
53-
web: ^1.0.0
5453

5554
flutter_colorpicker: ^1.1.0
5655

@@ -61,7 +60,7 @@ dependencies:
6160

6261
# Plugins
6362
url_launcher: ^6.2.4
64-
flutter_keyboard_visibility: ^6.0.0
63+
flutter_keyboard_visibility_temp_fork: ^0.1.1
6564
quill_native_bridge: '>=10.5.14 <=10.6.2'
6665

6766
dev_dependencies:

0 commit comments

Comments
 (0)