0

My app has web support, and the web version works fine, but when I'm trying run this one on mobile I'm getting this error:

Invalid depfile: D:\AndroidStudioProjects\app\.dart_tool\flutter_build\242eec030db87a43f1788c8579309a46\kernel_snapshot.d
Invalid depfile: D:\AndroidStudioProjects\app\.dart_tool\flutter_build\242eec030db87a43f1788c8579309a46\kernel_snapshot.d
lib/pages/web/application/add_application.dart:15:8: Error: Not found: 'dart:html'
import 'dart:html' as html;
       ^
/D:/SDKFlutter/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_web-2.0.2/lib/image_picker_web.dart:5:8: Error: Not found: 'dart:html'

And the thing is that I don't actually need dart:html in my mobile version, but I need it on web one, so is it able to run the app ignoring web files?

Just Mohit
  • 141
  • 1
  • 13
misterbobot
  • 92
  • 1
  • 7

1 Answers1

0

You can use conditional import. Based on your platform you can use any optional package. see this and see this

Simple way is make two widget and use ternary conditions, i.e.

import 'package:flutter/foundation.dart' show kIsWeb;

Container(
  child: kIsWeb ? WebPageUsedHTML() : NormalPage()
)
Reza M
  • 544
  • 3
  • 10