技术代码:Flutter

1Flutter SDK下载
2https://flutter.dev/docs/development/tools/sdk/releases?tab=windows#windows
3检查是否安装成功:
4flutter doctor
5安装包,类似npm install
6flutter packages get
7查看安装的包明细:
8flutter packages get --verbose
9启动项目:
10flutter packages pub global run webdev serve
11复制代码
参考地址:flutter-web与移动端兼容采坑
1Doctor summary (to see all details, run flutter doctor -v):
2[] Flutter (Channel dev, v0.1.7, on Mac OS X 10.12.6 16G1212, locale zh-Hans-CN)
3[] Android toolchain - develop for Android devices (Android SDK 27.0.0)
4[!] iOS toolchain - develop for iOS devices (Xcode 9.2)
5    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
6        brew install --HEAD libimobiledevice
7        brew install ideviceinstaller
8    ✗ ios-deploy not installed. To install:
9        brew install ios-deploy
10[] Android Studio (version 3.0)
11[] Connected devices (1 available)
参考地址:Flutter初体验(一)——Mac 安装配置
1class CounterState extends State<Counter> {
2  int counter = 0;
3
4  void increment() {
5    // 告诉Flutter state已经改变, Flutter会调用build(),更新显示
6    setState(() {
7      counter++;
8    });
9  }
10
11  Widget build(BuildContext context) {
12    // 当 setState 被调用时,这个方法都会重新执行.
13    // Flutter 对此方法做了优化,使重新执行变的很快
14    // 所以你可以重新构建任何需要更新的东西,而无需分别去修改各个widget
15    return new Row(
16      children: <Widget>[
17        new RaisedButton(
18          onPressed: increment,
19          child: new Text('Increment'),
20        ),
21        new Text('Count: $counter'),
22      ],
23    );
24  }
25}
参考地址:Flutter快速入门 五步搞定Flutter环境配置
1def scriptFile = getClass().protectionDomain.codeSource.location.path
2def flutterProjectRoot = new File(scriptFile).parentFile.parentFile
3
4gradle.include ':Flutter' //这里我把flutter改成了Flutter,因为我们的module都是大写字母开头
5gradle.project(':Flutter').projectDir = new File(flutterProjectRoot, 'FlutterClient/.android/Flutter')
6//这里两处修改project(':Flutter')同样是module大小写问题
7//另外一处是: new File(flutterProjectRoot, '.android/Flutter')改为 new File(flutterProjectRoot, 'FlutterClient/.android/Flutter')。修改之后,路径才是正确的。如果按照官网WIKI修改,不用修改就行。
8
9def plugins = new Properties()
10def pluginsFile = new File(flutterProjectRoot, 'FlutterClient/.flutter-plugins')
11if (pluginsFile.exists()) {
12    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
13}
14//这里一处修改def pluginsFile = new File(flutterProjectRoot, '.flutter-plugins')改为def pluginsFile = new File(flutterProjectRoot, 'FlutterClient/.flutter-plugins')。修改之后,插件module才会加载成功。如果按照官网WIKI修改,不用修改就行。
15
16plugins.each { name, path ->
17    def pluginDirectory = flutterProjectRoot.toPath().resolve(path).resolve('android').toFile()
18    println "plugin path is " + pluginDirectory.path
19    gradle.include ":$name"
20    gradle.project(":$name").projectDir = pluginDirectory
21}
22
23gradle.getGradle().projectsLoaded { g ->
24    g.rootProject.afterEvaluate { p ->
25        p.subprojects { sp ->
26            if (sp.name != 'flutter') {
27                sp.evaluationDependsOn(':Flutter')
28            }
29        }
30    }
31}
32//这里一处修改sp.evaluationDependsOn(':Flutter'),同前面大小写问题。
33复制代码
参考地址:Flutter-Android快速集成
1flutter renyugang$ tree -L 2 -d
2.
3├── bin
4│   ├── cache
5│   └── internal
6├── dev
7│   ├── automated_tests
8│   ├── benchmarks
9│   ├── bots
10│   ├── devicelab
11│   ├── docs
12│   ├── integration_tests
13│   ├── manual_tests
14│   ├── missing_dependency_tests
15│   └── tools
16├── examples
17│   ├── catalog
18│   ├── flutter_gallery
19│   ├── flutter_view
20│   ├── hello_world
21│   ├── layers
22│   ├── platform_channel
23│   ├── platform_channel_swift
24│   ├── platform_view
25│   └── stocks
26└── packages
27    ├── flutter
28    ├── flutter_driver
29    ├── flutter_localizations
30    ├── flutter_test
31    └── flutter_tools
3229 directories
参考地址:Flutter环境搭建(MAC)
1Performing hot reload...
2I/flutter (13770): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
3I/flutter (13770): The following assertion was thrown during performLayout():
4I/flutter (13770): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
5I/flutter (13770): When a column is in a parent that does not provide a finite height constraint, for example if it is
6I/flutter (13770): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
7I/flutter (13770): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
8I/flutter (13770): space in the vertical direction.
9I/flutter (13770): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
10I/flutter (13770): cannot simultaneously expand to fit its parent.
11I/flutter (13770): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
12I/flutter (13770): children (using Flexible rather than Expanded). This will allow the flexible children to size
13I/flutter (13770): themselves to less than the infinite remaining space they would otherwise be forced to take, and
14I/flutter (13770): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
15I/flutter (13770): constraints provided by the parent.
16I/flutter (13770): The affected RenderFlex is:
17I/flutter (13770):   RenderFlex#f6f9f relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT
18I/flutter (13770): The creator information is set to:
19I/flutter (13770):   Column ← RepaintBoundary-[<0>] ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
20I/flutter (13770):   AutomaticKeepAlive ← SliverList ← MediaQuery ← SliverPadding ← Viewport ← _ScrollableScope ←
21I/flutter (13770):   IgnorePointer-[GlobalKey#f8b80] ← Semantics ← ⋯
22I/flutter (13770): See also: https://flutter.io/layout/
23I/flutter (13770): If this message did not help you determine the problem, consider using debugDumpRenderTree():
24
25复制代码
参考地址:Flutter里ListView控件(新手)
1import 'package:flutter/material.dart';
2import 'package:url_launcher/url_launcher.dart';
3
4void main() {
5  runApp(new MyApp());
6}
7
8class MyApp extends StatelessWidget {
9  @override
10  Widget build(BuildContext context) {
11    return new MaterialApp(
12        title: 'Flutter Demo',
13        home: new DemoPage(),
14    );
15  }
16}
17
18class DemoPage extends StatelessWidget {
19  launchURL() {
20    launch('https://www.baidu.com/');
21  }
22
23  @override
24  Widget build(BuildContext context) {
25    return new Scaffold(
26      body: new Center(
27        child: new RaisedButton(
28          onPressed: launchURL,
29          child: new Text('百度首页'),
30        )
31      )
32    );
33  }
34}
参考地址:Flutter进阶—平台插件
1....
2....
3 @override
4  Widget build(BuildContext context) {
5    return Container(
6      color: Colors.blue,
7      child: Stack(
8        children: <Widget>[
9          Positioned(
10          //主要分析的Container对象
11            child: Container(
12            //_keyRed 申明为全局变量 GlobalKey _keyRed = GlobalKey();
13            //用key绑定Container
14              key: _keyRed,
15              decoration: BoxDecoration(color: Colors.yellow),
16              child: Row(
17                children: <Widget>[
18                ],
19              ),
20            ),
21          ),
22          Positioned(
23              child: Row(
24            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
25            children: <Widget>[
26              MaterialButton(
27                elevation: 5.0,
28                padding: EdgeInsets.all(15.0),
29                color: Colors.grey,
30                child: Text("Get Sizes"),
31                onPressed: _getSizes,
32              ),
33              MaterialButton(
34                elevation: 5.0,
35                color: Colors.grey,
36                padding: EdgeInsets.all(15.0),
37                child: Text("Get Positions"),
38                onPressed: _getPositions,
39              ),
40            ],
41          )),
42        ],
43      ),
44    );
45    //获取Positioned中Container渲染位置
46  _getPositions() {
47    final RenderBox renderBoxRed = _keyRed.currentContext.findRenderObject();
48    final positionRed = renderBoxRed.localToGlobal(Offset.zero);
49    print("POSITION of Red: $positionRed ");
50  }
51//获取Positioned中Container大小
52  _getSizes() {
53    final RenderBox renderBoxRed = _keyRed.currentContext.findRenderObject();
54    final sizeRed = renderBoxRed.size;
55    print("SIZE of Red: $sizeRed");
56  }
57复制代码
参考地址:Flutter 布局篇 Positioned 和 Container
1void testScheduleMicrotatsk() {
2  scheduleMicrotask(() => print('Mission_1'));
3
4//注释1
5  new Future.delayed(new Duration(seconds: 1), () => print('Mission_2'));
6
7//注释2
8  new Future(() => print('Mission_3')).then((_) {
9    print('Mission_4');
10    scheduleMicrotask(() => print('Mission_5'));
11  }).then((_) => print('Mission_6'));
12
13//注释3
14  new Future(() => print('Mission_7'))
15      .then((_) => new Future(() => print('Mission_8')))
16      .then((_) => print('Mission_9'));
17
18//注释4
19  new Future(() => print('Mission_10'));
20
21  scheduleMicrotask(() => print('Mission_11'));
22
23  print('Mission_12');
24}
25
26复制代码
参考地址:Flutter 事件机制 - Future 和 MicroTask 全解析
1$ flutter doctor -v
2[] Flutter (Channel master, v0.5.7-pre.55, on Mac OS X 10.13.4 17E199, locale zh-Hans-CN)
3    • Flutter version 0.5.7-pre.55 at /Users/iOSCMB/code/flutterSDK/flutter
4    • Framework revision 06f63aaa5a (9 hours ago), 2018-07-04 16:55:22 -0700
5    • Engine revision 21c7d6a5da
6    • Dart version 2.0.0-dev.63.0.flutter-4c9689c1d2
7
8[!] Android toolchain - develop for Android devices (Android SDK 28.0.1)
9    • Android SDK at /Users/iOSCMB/AndroidStudio/SDK
10    • Android NDK at /Users/iOSCMB/AndroidStudio/SDK/ndk-bundle
11    • Platform android-28, build-tools 28.0.1
12    • ANDROID_HOME = /Users/iOSCMB/AndroidStudio/SDK
13    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
14    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
15    ✗ Android license status unknown.
16
17[!] iOS toolchain - develop for iOS devices (Xcode 9.3)
18    • Xcode at /Applications/Xcode.app/Contents/Developer
19    • Xcode 9.3, Build version 9E145
20    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
21        brew install --HEAD libimobiledevice
22        brew install ideviceinstaller
23    ✗ ios-deploy not installed. To install:
24        brew install ios-deploy
25    • CocoaPods version 1.5.3
26
27[] Android Studio (version 3.1)
28    • Android Studio at /Applications/Android Studio.app/Contents
29    • Flutter plugin version 26.0.1
30    • Dart plugin version 173.4700
31    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
32
33[!] Connected devices
34    ! No devices available
参考地址:查看 flutter 安装其它依赖项遇到的问题

代码交流 2021