0

I see following error when I try to merge mobile and web codebase in Flutter:

webdev could not run for this project.
This version of webdev does not support the `build_daemon` protocol used by your version of `build_runner`.
Please add a dev dependency on `build_daemon` with constraint: >=1.0.0 <2.0.0
pub finished with exit code 78

My pubspec.yaml looks like this:

environment:
  sdk: '>=2.2.0 <3.0.0'

dependencies:
  flutter_web: any
  flutter_web_ui: any

dev_dependencies:
  # Enables the `pub run build_runner` command
  build_runner: ^1.1.2
  # Includes the JavaScript compilers
  build_web_compilers: ^1.0.0

# flutter_web packages are not published to pub.dartlang.org
# These overrides tell the package tools to get them from GitHub
dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web_ui```

I'm confused about how can "shared code" can really be "shared" across multi-platform in Flutter (shared codebase being the most important feature in Flutter pitch) 
bianca
  • 7,004
  • 12
  • 43
  • 58
  • Remove the flutter_test dependency - and dart can be compiled into JavaScript which is how they can pull off flutter for web and native platforms. – Adrian Murray Jun 03 '19 at 12:25
  • @AdrianMurray: Sorry, I had wrong code snippet before. I updated code and respective error. Thanks for helping out ! – bianca Jun 03 '19 at 15:26
  • I'm seeing there are some differences in your pubspec vs what is shown on the repositroy: https://github.com/flutter/flutter_web#use-flutter_web-packages-from-git – Adrian Murray Jun 03 '19 at 15:31
  • namely the build_runner and build_web_compilers. You're using 'any' where the error is asking for specific constraints. This is in your dev_dependencies – Adrian Murray Jun 03 '19 at 15:33
  • I updated all deps same as https://github.com/flutter/flutter_web#use-flutter_web-packages-from-git, still same problem – bianca Jun 03 '19 at 16:00
  • Wondering if Flutter team has any examples for web + android/ios together in same project/shared code way. I see they have separate repo for web in samples: https://github.com/flutter/samples/tree/master/web – bianca Jun 03 '19 at 16:02
  • web and android/ios can't use the same codebase right now as web is still in preview and using a completely different dependency (flutter_web). As for your issue, take a look here: https://github.com/dart-lang/webdev/issues/375#issuecomment-491412030 – Adrian Murray Jun 03 '19 at 16:04
  • oh...ok. I wasn't aware of that. I was trying to run android/ios from web, and ran into these issue. I can run web fine. Thanks for the clarification. – bianca Jun 03 '19 at 16:09
  • 1
    You can create another project using the code you've written for ios/android, but it can't be the same project. This assumes you aren't using any plugins in that code as web doesn't have a plugin system. – Adrian Murray Jun 03 '19 at 16:18
  • 1
    You might find this article helpful: https://github.com/flutter/flutter_web/blob/master/docs/migration_guide.md – Adrian Murray Jun 03 '19 at 16:20

2 Answers2

0

As mentioned in comments that it's not possible at this moment to be able to share web and native code base in one project. Please refer to this link if you've come across this post. It has instructions on the workaround available by Flutter team.

bianca
  • 7,004
  • 12
  • 43
  • 58
0

One solution I am working on is using javascript native in flutter by dart proxy. Copy your javascript code under Web/src and in the index.html file. script src the javascript code. In your main.dart import dart:js as js and use js.context.callMethod('your function',[your parameters] to invoke the javascript method.

I am forced too use javascript because flutter does not support qr reader for chrome.

Golden Lion
  • 3,840
  • 2
  • 26
  • 35