Merge pull request #37 from rish07/master

Fix Image Pick Issue on web
pull/41/head^2
Rishi Raj Singh 4 years ago committed by GitHub
commit bc03670a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      app/lib/pages/home_page.dart
  2. 86
      app/pubspec.lock
  3. 44
      lib/widgets/toolbar.dart
  4. 15
      pubspec.lock
  5. 2
      pubspec.yaml

@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -11,6 +10,7 @@ import 'package:flutter_quill/widgets/controller.dart';
import 'package:flutter_quill/widgets/default_styles.dart';
import 'package:flutter_quill/widgets/editor.dart';
import 'package:flutter_quill/widgets/toolbar.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:tuple/tuple.dart';
@ -91,11 +91,11 @@ class _HomePageState extends State<HomePage> {
}
Widget _buildWelcomeEditor(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Container(
return SafeArea(
child: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.88,
color: Colors.white,
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
child: QuillEditor(
@ -110,26 +110,27 @@ class _HomePageState extends State<HomePage> {
expands: false,
padding: EdgeInsets.zero,
customStyles: DefaultStyles(
h1: DefaultTextBlockStyle(
TextStyle(
fontSize: 32.0,
color: Colors.black,
height: 1.15,
fontWeight: FontWeight.w300,
),
Tuple2(16.0, 0.0),
Tuple2(0.0, 0.0),
null),
sizeSmall: TextStyle(fontSize: 9.0)),
h1: DefaultTextBlockStyle(
TextStyle(
fontSize: 32.0,
color: Colors.black,
height: 1.15,
fontWeight: FontWeight.w300,
),
Tuple2(16.0, 0.0),
Tuple2(0.0, 0.0),
null),
sizeSmall: TextStyle(fontSize: 9.0),
),
),
),
),
Container(
child: QuillToolbar.basic(
controller: _controller,
onImagePickCallback: _onImagePickCallback),
)
],
Container(
child: QuillToolbar.basic(
controller: _controller,
onImagePickCallback: _onImagePickCallback),
),
],
),
);
}

@ -78,6 +78,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
file_picker:
dependency: transitive
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.6"
flutter:
dependency: "direct main"
description: flutter
@ -103,7 +124,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.12"
version: "0.3.0"
flutter_test:
dependency: "direct dev"
description: flutter
@ -177,6 +198,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.27"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+2"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+8"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+3"
pedantic:
dependency: transitive
description:
@ -191,6 +247,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.3"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
plugin_platform_interface:
dependency: transitive
description:
@ -198,6 +261,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
quill_delta:
dependency: transitive
description:
@ -343,6 +413,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.4+1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
zone_local:
dependency: transitive
description:

@ -1,7 +1,9 @@
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:flutter_quill/models/documents/attribute.dart';
import 'package:flutter_quill/models/documents/nodes/embed.dart';
@ -509,7 +511,11 @@ class ImageButton extends StatefulWidget {
}
class _ImageButtonState extends State<ImageButton> {
List<PlatformFile> _paths;
String _directoryPath;
String _extension;
final _picker = ImagePicker();
FileType _pickingType = FileType.any;
Future<String> _pickImage(ImageSource source) async {
final PickedFile pickedFile = await _picker.getImage(source: source);
@ -527,6 +533,42 @@ class _ImageButtonState extends State<ImageButton> {
return null;
}
Future<String> _pickImageWeb() async {
try {
_directoryPath = null;
_paths = (await FilePicker.platform.pickFiles(
type: _pickingType,
allowMultiple: false,
allowedExtensions: (_extension?.isNotEmpty ?? false)
? _extension?.replaceAll(' ', '')?.split(',')
: null,
))
?.files;
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
} catch (ex) {
print(ex);
}
var _fileName =
_paths != null ? _paths.map((e) => e.name).toString() : '...';
if (_paths != null) {
File file = File(_fileName);
if (file == null || widget.onImagePickCallback == null) return null;
// We simply return the absolute path to selected file.
try {
String url = await widget.onImagePickCallback(file);
print('Image uploaded and its url is $url');
return url;
} catch (error) {
print('Upload image error $error');
}
return null;
} else {
// User canceled the picker
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@ -541,7 +583,7 @@ class _ImageButtonState extends State<ImageButton> {
onPressed: () {
final index = widget.controller.selection.baseOffset;
final length = widget.controller.selection.extentOffset - index;
final image = _pickImage(widget.imageSource);
final image = kIsWeb ? _pickImageWeb() : _pickImage(widget.imageSource);
image.then((imageUploadUrl) => {
if (imageUploadUrl != null)
{

@ -71,6 +71,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
file_picker:
dependency: "direct main"
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.6"
flutter:
dependency: "direct main"
description: flutter
@ -82,7 +89,7 @@ packages:
name: flutter_colorpicker
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.4"
version: "0.3.5"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
@ -134,7 +141,7 @@ packages:
name: image_picker_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
version: "1.1.6"
js:
dependency: transitive
description:
@ -169,7 +176,7 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.2"
version: "1.10.0"
photo_view:
dependency: "direct main"
description:
@ -314,7 +321,7 @@ packages:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5+1"
version: "0.1.5+3"
url_launcher_windows:
dependency: transitive
description:

@ -21,6 +21,8 @@ dependencies:
image_picker: ^0.6.7+22
photo_view: ^0.10.3
universal_html: ^1.2.1
file_picker: ^2.1.6
dev_dependencies:
flutter_test:

Loading…
Cancel
Save