flutterForWeb启动超级简单

1.flutter_web hello_world

1.1安装webdev命令

   flutter pub global activate webdev

1.2 flutter pub upgrade

! flutter_web 0.0.0 from path ../../packages/flutter_web                
! flutter_web_ui 0.0.0 from path ../../packages/flutter_web_ui          
Running "flutter pub upgrade" in hello_world...                     9.5s


1.3 下载依赖

 pub get
Resolving dependencies... 
Warning: You are using these overridden dependencies:
! flutter_web 0.0.0 from path ../../packages/flutter_web
! flutter_web_ui 0.0.0 from path ../../packages/flutter_web_ui
Downloading build_runner 1.8.1...
Downloading dart_style 1.3.4...
Downloading build_runner_core 5.0.0...
Downloading build_resolvers 1.3.4...
Got dependencies!
Precompiling executables... (15.4s)
Precompiled build_runner:graph_inspector.
Precompiled build_runner:build_runner.

1.4 运行webdev serve


[WARNING] Throwing away cached asset graph due to version mismatch or corrupted asset graph.
[INFO] Reading cached asset graph completed, took 167ms
[INFO] Building new asset graph completed, took 1.4s
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[SEVERE] Throwing away cached asset graph due to version mismatch or corrupted asset graph.
[INFO] Serving `web` on http://127.0.0.1:8080
[INFO] Running build completed, took 24.5s
[INFO] Caching finalized dependency graph completed, took 200ms
[INFO] Succeeded after 24.7s with 558 outputs (3119 actions)


1.5  lib/main.dart

import 'package:flutter_web/material.dart';

void main() {
  runApp(new Text('Hello 大成,Flutter Web', textDirection: TextDirection.ltr));
}

1.6  web/main.dart

import 'package:flutter_web_ui/ui.dart' as ui;
import 'package:flutter_web.examples.hello_world/main.dart' as app;
import 'package:flutter_web.examples.hello_world/main.dart' as app;

main() async {
  await ui.webOnlyInitializePlatform();
  app.main();
}

1.7 源代码结构

flutterForWeb启动超级简单_第1张图片

上面的2个dart文件,还有pubspec.yaml安装依赖

 

2.运行效果

flutterForWeb启动超级简单_第2张图片

恭喜你运行成功了flutter_web

 

 

你可能感兴趣的:(Flutter实践大全)