Flutter Web代碼運行問題記錄

一. 打包問題

1. 提示依賴

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

在pubspec.yaml下dev_dependencies中添加依賴:

dev_dependencies:
  build_daemon: ^1.0.0

二. VSCode 按F5調試運行不起來

1. 提示版本低

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`.
A newer version of webdev is available which supports your version of the `build_daemon`. Please update.

查看了版本都沒有問題,最後認爲是VSCode使用的webdev版本問題(理論上用的和電腦一樣纔對),暫時使用命令方式 webdev serve來運行,過了幾天VSCode提示更新webdev版本,點擊更新後,自動就好了

2. 提示找不到main.dart

VSCode提示:

Error: Error when reading 'bin/main.dart': No such file or directory

看到.vscode包下的配置了bin/main.dart,也是奇怪

 "version": "0.2.0",
    "configurations": [
        {
            "name": "Dart",
            "program": "bin/main.dart",
            "request": "launch",
            "type": "dart"
        }
    ]

處理:將其修改爲 web/main.dart

3. webdev could not run for this project.

更新flutter和webdev後,出現運行項目運行不起來,flutter版本1.5.4-hotfix.2 ,wevdev版本2.1.0

  • 提示:

運行項目提示說pubspect.yaml找不到:

Could not find a file named "pubspec.yaml" in "/Users/xxxx/.pub-cache/git/flutter_web-1ed4317aa91038ba99531037ce00c04672c4bee1/packages/flutter_web_ui"

然後我乾脆刪除了這個flutter_web-的文件夾,然後重新deactivate了 wevdev

flutter pub global deactivate webdev

再重新執行

flutter pub global activate webdev

再進行項目的執行,問題又來了:

webdev could not run for this project.
Could not find a file named "pubspec.yaml" in "/Users/shixin/.pub-cache/hosted/pub.flutter-io.cn/protobuf-0.13.12".

接下來我又修改了項目的pubspec.yaml文件,

build_daemon: ^1.0.0

to

build_daemon: ^1.1.0

再同步一下,pub get後,運行項目,項目能運行了,新問題來了,一直處於launching狀態,很是尷尬啊!

  • 再嘗試打包工程:
webdev build

看到控制檯有輸出:

[WARNING]build_web_compilers:entrypoint on web/main.dart: Skipping compiling flutter_web_demo|web/main.dart with dart2js because some of its
transitive libraries have sdk dependencies that not supported on this platform:

dio|lib/src/dio.dart
dio|lib/src/transformer.dart
dio|lib/src/interceptors/cookie_mgr.dart
dio|lib/src/response.dart
dio|lib/src/dio_http_headers.dart
dio|lib/src/upload_file_info.dart
dio|lib/src/options.dart
dio|lib/src/form_data.dart
dio|lib/src/adapter.dart
cookie_jar|lib/src/persist_cookie_jar.dart
cookie_jar|lib/src/default_cookie_jar.dart
cookie_jar|lib/src/serializable_cookie.dart
cookie_jar|lib/src/cookie_jar.dart

反應過來我使用到dio的,然後將dio的使用去掉就ok了,去掉dio的使用,代碼裏去掉dio的import和dio相關使用:

import 'package:flutter_web/material.dart';
// import 'package:dio/dio.dart';

很奇怪的是,之前webdev還是2.0.6-2.0.7都能用的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章