1
votes

A few months ago I made an android application using flutter. The application requires various dependencies such as intl, cached network image, stopper, carousel_slider, etc.

Then right now I want to convert the project to flutter_web. Here are the steps that I did:

  1. clone github web flutter
  2. I run the command "flutter packages pub global activate webdev"
  3. Then I edited pubspec.yaml and I adjusted it to pubspec.yaml in the previous project (android project)

Here is the contents of pubspec.yaml on the web flutter project:

name: flutter_web.examples.hello_world

environment:
  # You must be using Flutter> = 1.5.0 or Dart> = 2.3.0
  sdk: '> = 2.3.0-dev.0.1 <3.0.0'

dependencies:
  flutter_web: any
  flutter_web_ui: any
  stopper: ^ 1.0.1

dev_dependencies:
  build_runner: ^ 1.4.0
  build_web_compilers: ^ 2.0.0

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
  provider:
    git:
      url: https://github.com/kevmoo/provider
      ref: flutter_web

When I run 'pub dev', an error occurs while resolving the package stopper. Then I tried to open github from the package stopper (https://github.com/aryzhov/flutter-stopper), after that I checked the files in the lib folder. There I found a file called stopper.dart. It turns out that in the file, still using  import 'package: flutter / material.dart'; So that makes my pubspec error. Because the code should be replaced with import 'package: flutter_web / material.dart';

Therefore, I tried to outsmart the problem by removing the dependency stopper on pubspec.yaml, then I created a stopper.dart file manually, then I saved it in the lib/mypackages folder. After that, I import stopper.dart from the lib/mypackages folder (it's no longer through the package).

The package stopper is just one of the packages that I use on my Android project. Actually there are many other packages that have the same problem as the package stopper. The point is I have to create the package files manually, then I change "package: flutter / ..." to "package: flutter_web /" manually, then I can import them.

What I want to ask, is there a more elegant and simple way?

1

1 Answers

1
votes

Hi the instruction you are following is from an old repository here. As you can see this is discontinued. You can find the informaiton in the REadme.

Instead you should follow the instructions in this page. Read it once carefully and I would suggest to keep a backup of your main project and work on a copy.

  1. First you will have to enable the flutter-web using flutter config --enable-web.
  2. Then you will have to run flutter create .