Skip to content

Commit

Permalink
Avoid importing dart:io directly (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
daohoangson authored Feb 26, 2021
1 parent 350e8d1 commit 5037175
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/core/lib/src/core_widget_factory.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:io';

import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

import 'internal/core_ops.dart';
import 'internal/core_parser.dart';
import 'internal/platform_specific/fallback.dart'
if (dart.library.io) 'internal/platform_specific/io.dart';
import 'core_data.dart';
import 'core_helpers.dart';
import 'core_html_widget.dart';
Expand Down Expand Up @@ -340,7 +340,7 @@ class WidgetFactory {
final filePath = Uri.parse(url).toFilePath();
if (filePath.isEmpty) return null;

return FileImage(File(filePath));
return fileImageProvider(filePath);
}

/// Returns a [NetworkImage].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flutter/widgets.dart';

ImageProvider? fileImageProvider(String path) => null;
5 changes: 5 additions & 0 deletions packages/core/lib/src/internal/platform_specific/io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'dart:io';

import 'package:flutter/widgets.dart';

ImageProvider? fileImageProvider(String path) => FileImage(File(path));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flutter_svg/flutter_svg.dart';

PictureProvider filePictureProvider(String path) => null;
6 changes: 6 additions & 0 deletions packages/enhanced/lib/src/internal/platform_specific/io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'dart:io';

import 'package:flutter_svg/flutter_svg.dart';

PictureProvider filePictureProvider(String path) =>
FilePicture(SvgPicture.svgByteDecoder, File(path));
6 changes: 3 additions & 3 deletions packages/enhanced/lib/src/widget_factory.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -10,6 +8,8 @@ import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart

import 'external/url_launcher.dart';
import 'internal/ops.dart';
import 'internal/platform_specific/fallback.dart'
if (dart.library.io) 'internal/platform_specific/io.dart';
import 'data.dart';
import 'helpers.dart';
import 'html_widget.dart';
Expand Down Expand Up @@ -197,7 +197,7 @@ class WidgetFactory extends core.WidgetFactory {
final filePath = Uri.parse(url).toFilePath();
if (filePath.isEmpty) return null;

return FilePicture(SvgPicture.svgByteDecoder, File(filePath));
return filePictureProvider(filePath);
}

/// Returns a [NetworkPicture].
Expand Down

1 comment on commit 5037175

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.