Skip to content

Commit

Permalink
feat: add dark theme for example project
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jun 30, 2023
1 parent dbf8e0d commit 88d52d0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 63 deletions.
6 changes: 2 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class MyApp extends StatelessWidget {
supportedLocales: const [Locale('en', 'US')],
debugShowCheckedModeBanner: false,
home: const MyHomePage(title: 'AppFlowyEditor Example'),
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
theme: ThemeData.light(useMaterial3: true),
darkTheme: ThemeData.dark(useMaterial3: true),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export 'delta_input_on_delete_impl.dart';
export 'delta_input_on_insert_impl.dart';
export 'delta_input_on_non_text_update_impl.dart';
export 'delta_input_on_replace_impl.dart';
export 'non_delta_input_service.dart';
export 'text_input_service.dart';
Original file line number Diff line number Diff line change
@@ -1,48 +1,9 @@
import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_input_service.dart';
import 'package:flutter/services.dart';

abstract class TextInputService {
TextInputService({
required this.onInsert,
required this.onDelete,
required this.onReplace,
required this.onNonTextUpdate,
required this.onPerformAction,
});

Future<void> Function(TextEditingDeltaInsertion insertion) onInsert;
Future<void> Function(TextEditingDeltaDeletion deletion) onDelete;
Future<void> Function(TextEditingDeltaReplacement replacement) onReplace;
Future<void> Function(TextEditingDeltaNonTextUpdate nonTextUpdate)
onNonTextUpdate;
Future<void> Function(TextInputAction action) onPerformAction;

TextRange? get composingTextRange;
bool get attached;

void updateCaretPosition(Size size, Matrix4 transform, Rect rect);

/// Updates the [TextEditingValue] of the text currently being edited.
///
/// Note that if there are IME-related requirements,
/// please config `composing` value within [TextEditingValue]
///
/// [BuildContext] is used to get current keyboard appearance(light or dark)
void attach(TextEditingValue textEditingValue, BuildContext context);

/// Applies insertion, deletion and replacement
/// to the text currently being edited.
///
/// For more information, please check [TextEditingDelta].
Future<void> apply(List<TextEditingDelta> deltas);

/// Closes the editing state of the text currently being edited.
void close();
}

class DeltaTextInputService extends TextInputService with DeltaTextInputClient {
DeltaTextInputService({
required super.onInsert,
Expand Down Expand Up @@ -85,18 +46,22 @@ class DeltaTextInputService extends TextInputService with DeltaTextInputClient {
}

@override
void attach(TextEditingValue textEditingValue, BuildContext context) {
void attach(
TextEditingValue textEditingValue,
TextInputConfiguration configuration,
) {
if (_textInputConnection == null ||
_textInputConnection!.attached == false) {
_textInputConnection = TextInput.attach(
this,
TextInputConfiguration(
enableDeltaModel: true,
inputType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
inputAction: TextInputAction.newline,
keyboardAppearance: Theme.of(context).brightness,
),
configuration,
// TextInputConfiguration(
// enableDeltaModel: true,
// inputType: TextInputType.multiline,
// textCapitalization: TextCapitalization.sentences,
// inputAction: TextInputAction.newline,
// keyboardAppearance: Theme.of(context).brightness,
// ),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_diff.dart';
import 'package:flutter/material.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_input_service.dart';
import 'package:flutter/services.dart';

class NonDeltaTextInputService extends TextInputService with TextInputClient {
Expand Down Expand Up @@ -57,7 +57,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
@override
void attach(
TextEditingValue textEditingValue,
BuildContext context,
TextInputConfiguration configuration,
) {
final formattedValue = textEditingValue.format();
if (currentTextEditingValue == formattedValue) {
Expand All @@ -68,13 +68,14 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
_textInputConnection!.attached == false) {
_textInputConnection = TextInput.attach(
this,
TextInputConfiguration(
enableDeltaModel: false,
inputType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
inputAction: TextInputAction.newline,
keyboardAppearance: Theme.of(context).brightness,
),
configuration,
// TextInputConfiguration(
// enableDeltaModel: false,
// inputType: TextInputType.multiline,
// textCapitalization: TextCapitalization.sentences,
// inputAction: TextInputAction.newline,
// keyboardAppearance: Theme.of(context).brightness,
// ),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

abstract class TextInputService {
TextInputService({
required this.onInsert,
required this.onDelete,
required this.onReplace,
required this.onNonTextUpdate,
required this.onPerformAction,
});

Future<void> Function(TextEditingDeltaInsertion insertion) onInsert;
Future<void> Function(TextEditingDeltaDeletion deletion) onDelete;
Future<void> Function(TextEditingDeltaReplacement replacement) onReplace;
Future<void> Function(TextEditingDeltaNonTextUpdate nonTextUpdate)
onNonTextUpdate;
Future<void> Function(TextInputAction action) onPerformAction;

TextRange? get composingTextRange;
bool get attached;

void updateCaretPosition(Size size, Matrix4 transform, Rect rect);

/// Updates the [TextEditingValue] of the text currently being edited.
///
/// Note that if there are IME-related requirements,
/// please config `composing` value within [TextEditingValue]
///
/// [BuildContext] is used to get current keyboard appearance(light or dark)
void attach(
TextEditingValue textEditingValue,
TextInputConfiguration configuration,
);

/// Applies insertion, deletion and replacement
/// to the text currently being edited.
///
/// For more information, please check [TextEditingDelta].
Future<void> apply(List<TextEditingDelta> deltas);

/// Closes the editing state of the text currently being edited.
void close();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/ime/non_delta_input_service.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -200,7 +199,13 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
if (textEditingValue != null) {
textInputService.attach(
textEditingValue,
context,
TextInputConfiguration(
enableDeltaModel: false,
inputType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
inputAction: TextInputAction.newline,
keyboardAppearance: Theme.of(context).brightness,
),
);
// disable shortcuts when the IME active
enableShortcuts = textEditingValue.composing == TextRange.empty;
Expand Down

0 comments on commit 88d52d0

Please sign in to comment.