Skip to content

Commit

Permalink
Update extensions and example
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoEllet committed Nov 6, 2023
1 parent b9b1ecb commit f0d0110
Show file tree
Hide file tree
Showing 25 changed files with 466 additions and 217 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [8.2.3]
- Update `README.md`

## [8.2.2]
- Move the `flutter_quill_test` to seperated package [flutter_quill_test](https://pub.dev/packages/flutter_quill_test)

Expand Down
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ Pub: [FlutterQuill]
- [Custom Buttons](#custom-buttons)
- [Embed Blocks](#embed-blocks)
- [Using the embed blocks from `flutter_quill_extensions`](#using-the-embed-blocks-from-flutter_quill_extensions)
- [Custom Size Image for Mobile](#custom-size-image-for-mobile)
- [Custom Size Image for other platforms (excluding web)](#custom-size-image-for-other-platforms-excluding-web)
- [Custom Embed Blocks](#custom-embed-blocks)
- [Custom Toolbar](#custom-toolbar)
- [Translation](#translation)
Expand Down Expand Up @@ -253,36 +251,6 @@ Provide a list of embed

To see how to use the extensions package, please take a look at the [README](./flutter_quill_extensions/README.md) of [FlutterQuill Extensions]

### Custom Size Image for Mobile

Define `mobileWidth`, `mobileHeight`, `mobileMargin`, `mobileAlignment` as follows:

```json
{
"insert": {
"image": "https://user-images.githubusercontent.com/122956/72955931-ccc07900-3d52-11ea-89b1-d468a6e2aa2b.png"
},
"attributes":{
"style":"mobileWidth: 50; mobileHeight: 50; mobileMargin: 10; mobileAlignment: topLeft"
}
}
```

### Custom Size Image for other platforms (excluding web)

Define `width`, `height`, `margin`, `alignment` as follows:

```json
{
"insert": {
"image": "https://user-images.githubusercontent.com/122956/72955931-ccc07900-3d52-11ea-89b1-d468a6e2aa2b.png"
},
"attributes":{
"style":"width: 50; height: 50; margin: 10; alignment: topLeft"
}
}
```

### Custom Embed Blocks

Sometimes you want to add some custom content inside your text, custom widgets inside of them. An example is adding notes to the text, or anything custom that you want to add in your text editor.
Expand Down
2 changes: 1 addition & 1 deletion example/assets/sample_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@
},
"attributes": {
"width": "230",
"style": "display: block; margin: auto;"
"style": "display: block; margin: auto; width: 500px;"
}
},
{
Expand Down
10 changes: 0 additions & 10 deletions example/assets/sample_data_nomedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@
},
"insert": " and "
},
{
"attributes": {
"strike": true,
"color": "black"
},
"insert": "web"
},
{
"insert": " is not supported.\nYou are welcome to use "
},
{
"attributes": {
"link": "https://bulletjournal.us/home/index.html"
Expand Down
97 changes: 97 additions & 0 deletions example/assets/sample_data_testing.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ class _HomePageState extends State<HomePage> {

Future<void> _loadFromAssets() async {
try {
final result = await rootBundle.loadString(isDesktop()
? 'assets/sample_data_nomedia.json'
: 'assets/sample_data.json');
final result =
await rootBundle.loadString('assets/sample_data_testing.json');
// final result = await rootBundle.loadString(isDesktop()
// ? 'assets/sample_data_nomedia.json'
// : 'assets/sample_data.json');
final doc = Document.fromJson(jsonDecode(result));
_controller = QuillController(
document: doc,
selection: const TextSelection.collapsed(offset: 0),
);
} catch (error) {
final doc = Document()..insert(0, 'Empty asset');
final doc = Document()
..insert(0, 'Error while loading the document: ${error.toString()}');
_controller = QuillController(
document: doc,
selection: const TextSelection.collapsed(offset: 0),
Expand Down
195 changes: 96 additions & 99 deletions example/lib/universal_ui/universal_ui.dart
Original file line number Diff line number Diff line change
@@ -1,118 +1,115 @@
library universal_ui;

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
import 'package:universal_html/html.dart' as html;
import 'package:youtube_player_flutter/youtube_player_flutter.dart';

import '../widgets/responsive_widget.dart';
import 'fake_ui.dart' if (dart.library.html) 'real_ui.dart' as ui_instance;
// import '../widgets/responsive_widget.dart';
// import 'fake_ui.dart' if (dart.library.html) 'real_ui.dart' as ui_instance;

class PlatformViewRegistryFix {
void registerViewFactory(dynamic x, dynamic y) {
if (kIsWeb) {
ui_instance.PlatformViewRegistry.registerViewFactory(
x,
y,
);
}
}
}
// class PlatformViewRegistryFix {
// void registerViewFactory(dynamic x, dynamic y) {
// if (kIsWeb) {
// ui_instance.PlatformViewRegistry.registerViewFactory(
// x,
// y,
// );
// }
// }
// }

class UniversalUI {
PlatformViewRegistryFix platformViewRegistry = PlatformViewRegistryFix();
}
// class UniversalUI {
// PlatformViewRegistryFix platformViewRegistry = PlatformViewRegistryFix();
// }

var ui = UniversalUI();
// var ui = UniversalUI();

class ImageEmbedBuilderWeb extends EmbedBuilder {
@override
String get key => BlockEmbed.imageType;
// class ImageEmbedBuilderWeb extends EmbedBuilder {
// @override
// String get key => BlockEmbed.imageType;

@override
Widget build(
BuildContext context,
QuillController controller,
Embed node,
bool readOnly,
bool inline,
TextStyle textStyle,
) {
final imageUrl = node.value.data;
if (isImageBase64(imageUrl)) {
// TODO: handle imageUrl of base64
return const SizedBox();
}
final size = MediaQuery.sizeOf(context);
UniversalUI().platformViewRegistry.registerViewFactory(imageUrl, (viewId) {
return html.ImageElement()
..src = imageUrl
..style.height = 'auto'
..style.width = 'auto';
});
return Padding(
padding: EdgeInsets.only(
right: ResponsiveWidget.isMediumScreen(context)
? size.width * 0.5
: (ResponsiveWidget.isLargeScreen(context))
? size.width * 0.75
: size.width * 0.2,
),
child: SizedBox(
height: size.height * 0.45,
child: HtmlElementView(
viewType: imageUrl,
),
),
);
}
}
// @override
// Widget build(
// BuildContext context,
// QuillController controller,
// Embed node,
// bool readOnly,
// bool inline,
// TextStyle textStyle,
// ) {
// final imageUrl = node.value.data;
// if (isImageBase64(imageUrl)) {
// // TODO: handle imageUrl of base64
// return const SizedBox();
// }
// final size = MediaQuery.sizeOf(context);
// UniversalUI().platformViewRegistry.registerViewFactory(imageUrl,
//(viewId) {
// return html.ImageElement()
// ..src = imageUrl
// ..style.height = 'auto'
// ..style.width = 'auto';
// });
// return Padding(
// padding: EdgeInsets.only(
// right: ResponsiveWidget.isMediumScreen(context)
// ? size.width * 0.5
// : (ResponsiveWidget.isLargeScreen(context))
// ? size.width * 0.75
// : size.width * 0.2,
// ),
// child: SizedBox(
// height: size.height * 0.45,
// child: HtmlElementView(
// viewType: imageUrl,
// ),
// ),
// );
// }
// }

class VideoEmbedBuilderWeb extends EmbedBuilder {
@override
String get key => BlockEmbed.videoType;
// class VideoEmbedBuilderWeb extends EmbedBuilder {
// @override
// String get key => BlockEmbed.videoType;

@override
Widget build(
BuildContext context,
QuillController controller,
Embed node,
bool readOnly,
bool inline,
TextStyle textStyle,
) {
var videoUrl = node.value.data;
if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) {
final youtubeID = YoutubePlayer.convertUrlToId(videoUrl);
if (youtubeID != null) {
videoUrl = 'https://www.youtube.com/embed/$youtubeID';
}
}
// @override
// Widget build(
// BuildContext context,
// QuillController controller,
// Embed node,
// bool readOnly,
// bool inline,
// TextStyle textStyle,
// ) {
// var videoUrl = node.value.data;
// if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) {
// final youtubeID = YoutubePlayer.convertUrlToId(videoUrl);
// if (youtubeID != null) {
// videoUrl = 'https://www.youtube.com/embed/$youtubeID';
// }
// }

final size = MediaQuery.sizeOf(context);
// final size = MediaQuery.sizeOf(context);

UniversalUI().platformViewRegistry.registerViewFactory(
videoUrl,
(id) => html.IFrameElement()
..width = size.width.toString()
..height = size.height.toString()
..src = videoUrl
..style.border = 'none',
);
// UniversalUI().platformViewRegistry.registerViewFactory(
// videoUrl,
// (id) => html.IFrameElement()
// ..width = size.width.toString()
// ..height = size.height.toString()
// ..src = videoUrl
// ..style.border = 'none',
// );

return SizedBox(
height: 500,
child: HtmlElementView(
viewType: videoUrl,
),
);
}
}
// return SizedBox(
// height: 500,
// child: HtmlElementView(
// viewType: videoUrl,
// ),
// );
// }
// }

List<EmbedBuilder> get defaultEmbedBuildersWeb => [
...FlutterQuillEmbeds.editorsWebBuilders(),
// ImageEmbedBuilderWeb(),
const QuillEditorWebImageEmbedBuilder(),
VideoEmbedBuilderWeb(),
// VideoEmbedBuilderWeb(),
];
4 changes: 4 additions & 0 deletions flutter_quill_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0-dev.6
- Better support for web
- Smal fixes and updates

## 0.6.0-dev.5
- Update the camera button

Expand Down
37 changes: 37 additions & 0 deletions flutter_quill_extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Currently the support for **Web** is limitied.
- [Installation](#installation)
- [Platform Spesefic Configurations](#platform-spesefic-configurations)
- [Usage](#usage)
- [Embed Blocks](#embed-blocks)
- [Custom Size Image for Mobile](#custom-size-image-for-mobile)
- [Custom Size Image for other platforms (excluding web)](#custom-size-image-for-other-platforms-excluding-web)
- [Features](#features)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -110,6 +113,40 @@ QuillProvider(
)
```

## Embed Blocks

As of version [flutter_quill](https://pub.dev/packages/flutter_quill) 6.0, embed blocks are not provided by default as part of Flutter quill. Instead, it provides an interface to all the user to provide there own implementations for embed blocks. Implementations for image, video and formula embed blocks is proved in this package

### Custom Size Image for Mobile

Define `mobileWidth`, `mobileHeight`, `mobileMargin`, `mobileAlignment` as follows:

```json
{
"insert": {
"image": "https://user-images.githubusercontent.com/122956/72955931-ccc07900-3d52-11ea-89b1-d468a6e2aa2b.png"
},
"attributes":{
"style":"mobileWidth: 50; mobileHeight: 50; mobileMargin: 10; mobileAlignment: topLeft"
}
}
```

### Custom Size Image for other platforms (excluding web)

Define `width`, `height`, `margin`, `alignment` as follows:

```json
{
"insert": {
"image": "https://user-images.githubusercontent.com/122956/72955931-ccc07900-3d52-11ea-89b1-d468a6e2aa2b.png"
},
"attributes": {
"style":"width: 50; height: 50; margin: 10; alignment: topLeft"
}
}
```

## Features

```markdown
Expand Down
Loading

0 comments on commit f0d0110

Please sign in to comment.