Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace flutter_keyboard_visibility with flutter_keyboard_visibility_temp_fork to support Flutter/Wasm target #2293

Merged
merged 6 commits into from
Sep 27, 2024
10 changes: 0 additions & 10 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart'
Expand All @@ -9,10 +8,6 @@ import 'package:flutter_localizations/flutter_localizations.dart'
import 'package:flutter_quill/flutter_quill.dart' show Document;
import 'package:flutter_quill/translations.dart' show FlutterQuillLocalizations;
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart'
show HydratedBloc, HydratedStorage;
import 'package:path_provider/path_provider.dart'
show getApplicationDocumentsDirectory;

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

void main() async {
WidgetsFlutterBinding.ensureInitialized();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
: await getApplicationDocumentsDirectory(),
);
// ignore: deprecated_member_use
FlutterQuillExtensions.useSuperClipboardPlugin();
runApp(const MyApp());
Expand Down
14 changes: 2 additions & 12 deletions example/lib/screens/settings/cubit/settings_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import 'package:flutter/material.dart' show ThemeMode;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart' show HydratedCubit;

part 'settings_state.dart';
part 'settings_cubit.freezed.dart';
part 'settings_cubit.g.dart';

class SettingsCubit extends HydratedCubit<SettingsState> {
class SettingsCubit extends Cubit<SettingsState> {
SettingsCubit() : super(const SettingsState());

void updateSettings(SettingsState newSettingsState) {
emit(newSettingsState);
}

@override
SettingsState? fromJson(Map<String, dynamic> json) {
return SettingsState.fromJson(json);
}

@override
Map<String, dynamic>? toJson(SettingsState state) {
return state.toJson();
}
}
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dependencies:
# Bloc libraries
bloc: ^8.1.4
flutter_bloc: ^8.1.5
hydrated_bloc: ^9.1.5

# Freezed
freezed_annotation: ^2.4.1
Expand Down
13 changes: 1 addition & 12 deletions lib/src/controller/quill_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:math' as math;

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/services.dart' show ClipboardData, Clipboard;
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart' show experimental;
Expand All @@ -21,9 +20,6 @@ import '../toolbar/config/simple_toolbar_configurations.dart';
import 'quill_controller_configurations.dart';
import 'quill_controller_rich_paste.dart';

import 'web/quill_controller_web_stub.dart'
if (dart.library.html) 'web/quill_controller_web_real.dart';

typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
typedef DeleteCallback = void Function(int cursorPosition, bool forward);

Expand All @@ -40,11 +36,7 @@ class QuillController extends ChangeNotifier {
this.readOnly = false,
this.editorFocusNode,
}) : _document = document,
_selection = selection {
if (kIsWeb) {
initializeWebPasteEvent();
}
}
_selection = selection;

factory QuillController.basic(
{QuillControllerConfigurations configurations =
Expand Down Expand Up @@ -476,9 +468,6 @@ class QuillController extends ChangeNotifier {
}

_isDisposed = true;
if (kIsWeb) {
cancelWebPasteEvent();
}
super.dispose();
}

Expand Down
66 changes: 35 additions & 31 deletions lib/src/controller/web/quill_controller_web_real.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
// TODO: This might be removed from here or moved to quill_native_bridge
// commented in https://github.com/singerdmx/flutter-quill/pull/2293
// removed due to bug https://github.com/singerdmx/flutter-quill/issues/2220
// added to solve https://github.com/singerdmx/flutter-quill/issues/1998#issuecomment-2361599854

// This file should not be exported as the APIs in it are meant for internal usage only

import 'dart:async' show StreamSubscription;
// import 'dart:async' show StreamSubscription;

import 'package:web/web.dart';
// import 'package:web/web.dart';

import '../quill_controller.dart';
// ignore: unused_import
import '../quill_controller_rich_paste.dart';
// import '../quill_controller.dart';
// // ignore: unused_import
// import '../quill_controller_rich_paste.dart';

/// Paste event for the web.
///
/// Will be `null` when [QuillControllerWeb.initializeWebPasteEvent] was not called
/// or the subscription was canceled due to calling [QuillControllerWeb.cancelWebPasteEvent]
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
StreamSubscription? _webPasteEventSubscription;
// /// Paste event for the web.
// ///
// /// Will be `null` when [QuillControllerWeb.initializeWebPasteEvent] was not called
// /// or the subscription was canceled due to calling [QuillControllerWeb.cancelWebPasteEvent]
// ///
// /// See: https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
// StreamSubscription? _webPasteEventSubscription;

extension QuillControllerWeb on QuillController {
void initializeWebPasteEvent() {
_webPasteEventSubscription =
EventStreamProviders.pasteEvent.forTarget(window.document).listen((e) {
// TODO: See if we can support markdown paste
final html = e.clipboardData?.getData('text/html');
if (html == null) {
return;
}
// TODO: Temporarily disable the rich text pasting feature as a workaround
// due to issue https://github.com/singerdmx/flutter-quill/issues/2220
// pasteHTML(html: html);
});
}
// extension QuillControllerWeb on QuillController {
// void initializeWebPasteEvent() {
// _webPasteEventSubscription =
// EventStreamProviders.pasteEvent.forTarget(window.document).listen((e) {
// final html = e.clipboardData?.getData('text/html');
// if (html == null) {
// return;
// }
// // TODO: Temporarily disable the rich text pasting feature as a workaround
// // due to issue https://github.com/singerdmx/flutter-quill/issues/2220
// // pasteHTML(html: html);
// });
// }

void cancelWebPasteEvent() {
_webPasteEventSubscription?.cancel();
_webPasteEventSubscription = null;
}
}
// void cancelWebPasteEvent() {
// _webPasteEventSubscription?.cancel();
// _webPasteEventSubscription = null;
// }
// }
35 changes: 19 additions & 16 deletions lib/src/controller/web/quill_controller_web_stub.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// This file should not be exported as the APIs in it are meant for internal usage only
// See quill_controller_web_real.dart if you want to know why this is not removed yet
// will be addressed in future releases.

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

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

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

void cancelWebPasteEvent() {
throw UnsupportedError(
'The closeWebPasteEvent() method should be called only on web.',
);
}
}
// extension QuillControllerWeb on QuillController {
// void initializeWebPasteEvent() {
// throw UnsupportedError(
// 'The initializeWebPasteEvent() method should be called only on web.',
// );
// }

// void cancelWebPasteEvent() {
// throw UnsupportedError(
// 'The closeWebPasteEvent() method should be called only on web.',
// );
// }
// }
2 changes: 1 addition & 1 deletion lib/src/editor/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:flutter/rendering.dart' show RenderAbstractViewport;
import 'package:flutter/scheduler.dart' show SchedulerBinding;
import 'package:flutter/services.dart'
show Clipboard, HardwareKeyboard, SystemChannels, TextInputControl;
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'
import 'package:flutter_keyboard_visibility_temp_fork/flutter_keyboard_visibility_temp_fork.dart'
show KeyboardVisibilityController;

import '../../common/structs/horizontal_spacing.dart';
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dependencies:
equatable: ^2.0.5
meta: ^1.10.0
html: ^0.15.4
web: ^1.0.0

flutter_colorpicker: ^1.1.0

Expand All @@ -61,7 +60,7 @@ dependencies:

# Plugins
url_launcher: ^6.2.4
flutter_keyboard_visibility: ^6.0.0
flutter_keyboard_visibility_temp_fork: ^0.1.1
quill_native_bridge: '>=10.5.14 <=10.6.2'

dev_dependencies:
Expand Down