Remove filesystem_picker dependency

pull/271/head
Xin Yao 4 years ago
parent 6dc4826734
commit 457c6e561b
  1. 12
      example/lib/pages/home_page.dart
  2. 12
      example/lib/widgets/demo_scaffold.dart
  3. 1
      example/pubspec.yaml
  4. 11
      lib/src/widgets/toolbar.dart
  5. 23
      lib/src/widgets/toolbar/image_button.dart
  6. 1
      pubspec.yaml

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:filesystem_picker/filesystem_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -145,7 +146,7 @@ class _HomePageState extends State<HomePage> {
toolbar = QuillToolbar.basic(
controller: _controller!,
onImagePickCallback: _onImagePickCallback,
applicationPath: getApplicationDirectoryForDesktop());
filePickImpl: openFileSystemPickerForDesktop);
}
return SafeArea(
@ -173,8 +174,13 @@ class _HomePageState extends State<HomePage> {
);
}
Future<Directory> getApplicationDirectoryForDesktop() async {
return await getApplicationDocumentsDirectory();
Future<String?> openFileSystemPickerForDesktop(BuildContext context) async {
return await FilesystemPicker.open(
context: context,
rootDirectory: await getApplicationDocumentsDirectory(),
fsType: FilesystemType.file,
fileTileSelectMode: FileTileSelectMode.wholeTile,
);
}
// Renders the image picked by imagePicker from local file storage

@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'package:filesystem_picker/filesystem_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -73,8 +74,13 @@ class _DemoScaffoldState extends State<DemoScaffold> {
}
}
Future<Directory> getApplicationDirectoryForDesktop() async {
return await getApplicationDocumentsDirectory();
Future<String?> openFileSystemPickerForDesktop(BuildContext context) async {
return await FilesystemPicker.open(
context: context,
rootDirectory: await getApplicationDocumentsDirectory(),
fsType: FilesystemType.file,
fileTileSelectMode: FileTileSelectMode.wholeTile,
);
}
@override
@ -85,7 +91,7 @@ class _DemoScaffoldState extends State<DemoScaffold> {
if (isDesktop) {
toolbar = QuillToolbar.basic(
controller: _controller!,
applicationPath: getApplicationDirectoryForDesktop());
filePickImpl: openFileSystemPickerForDesktop);
}
return Scaffold(
key: _scaffoldKey,

@ -29,6 +29,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
path_provider: ^2.0.1
filesystem_picker: ^2.0.0-nullsafety.0
flutter_quill:
path: ../

@ -33,6 +33,7 @@ export 'toolbar/toggle_style_button.dart';
typedef OnImagePickCallback = Future<String> Function(File file);
typedef ImagePickImpl = Future<String?> Function(ImageSource source);
typedef FilePickImpl = Future<String?> Function(BuildContext context);
// The default size of the icon of a button.
const double kDefaultIconSize = 18;
@ -45,7 +46,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
required this.children,
this.toolBarHeight = 36,
this.color,
this.applicationPath,
this.filePickImpl,
Key? key,
}) : super(key: key);
@ -70,7 +71,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
bool showHistory = true,
bool showHorizontalRule = false,
OnImagePickCallback? onImagePickCallback,
Future<Directory>? applicationPath,
FilePickImpl? filePickImpl,
Key? key,
}) {
final isButtonGroupShown = [
@ -162,7 +163,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller,
imageSource: ImageSource.gallery,
onImagePickCallback: onImagePickCallback,
applicationPath: applicationPath,
filePickImpl: filePickImpl,
),
if (onImagePickCallback != null)
ImageButton(
@ -171,7 +172,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller,
imageSource: ImageSource.camera,
onImagePickCallback: onImagePickCallback,
applicationPath: applicationPath,
filePickImpl: filePickImpl,
),
if (isButtonGroupShown[0] &&
(isButtonGroupShown[1] ||
@ -283,7 +284,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
/// is given.
final Color? color;
final Future<Directory>? applicationPath;
final FilePickImpl? filePickImpl;
@override
Size get preferredSize => Size.fromHeight(toolBarHeight);

@ -1,7 +1,6 @@
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:filesystem_picker/filesystem_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
@ -20,7 +19,7 @@ class ImageButton extends StatelessWidget {
this.fillColor,
this.onImagePickCallback,
this.imagePickImpl,
this.applicationPath,
this.filePickImpl,
Key? key,
}) : super(key: key);
@ -37,7 +36,7 @@ class ImageButton extends StatelessWidget {
final ImageSource imageSource;
final Future<Directory>? applicationPath;
final FilePickImpl? filePickImpl;
@override
Widget build(BuildContext context) {
@ -49,12 +48,12 @@ class ImageButton extends StatelessWidget {
hoverElevation: 0,
size: iconSize * 1.77,
fillColor: fillColor ?? theme.canvasColor,
onPressed: () => _handleImageButtonTap(context, applicationPath),
onPressed: () => _handleImageButtonTap(context, filePickImpl),
);
}
Future<void> _handleImageButtonTap(BuildContext context,
[Future<Directory>? applicationPath]) async {
[FilePickImpl? filePickImpl]) async {
final index = controller.selection.baseOffset;
final length = controller.selection.extentOffset - index;
@ -67,9 +66,8 @@ class ImageButton extends StatelessWidget {
} else if (Platform.isAndroid || Platform.isIOS) {
imageUrl = await _pickImage(imageSource);
} else {
assert(applicationPath != null,
'Desktop must provide application document directory');
imageUrl = await _pickImageDesktop(context, applicationPath!);
assert(filePickImpl != null, 'Desktop must provide filePickImpl');
imageUrl = await _pickImageDesktop(context, filePickImpl!);
}
}
@ -101,13 +99,8 @@ class ImageButton extends StatelessWidget {
}
Future<String?> _pickImageDesktop(
BuildContext context, Future<Directory> applicationPath) async {
final filePath = await FilesystemPicker.open(
context: context,
rootDirectory: await applicationPath,
fsType: FilesystemType.file,
fileTileSelectMode: FileTileSelectMode.wholeTile,
);
BuildContext context, FilePickImpl filePickImpl) async {
final filePath = await filePickImpl(context);
if (filePath == null || filePath.isEmpty) return null;
final file = File(filePath);

@ -14,7 +14,6 @@ dependencies:
sdk: flutter
collection: ^1.15.0
file_picker: ^3.0.2+2
filesystem_picker: ^2.0.0-nullsafety.0
flutter_colorpicker: ^0.4.0
flutter_keyboard_visibility: ^5.0.0
image_picker: ^0.7.3

Loading…
Cancel
Save