想了想,还是学Flutter吧。

首先用百度搜Flutter,搜到了 https://flutterchina.club/

然后进去看看新手教程,我用的是Windows系统

1. 安装Git

进去就说要先安装git,让我们先装git https://git-scm.com/download/win 。记得安装后添加到环境变量

2.安装Flutter SDK

有了这个才能写Flutter项目,直接下最新版,https://flutter.io/sdk-archive/#windows 。记住安装路径

3.安装Android Studio

我本来就是学安卓的,这个放个下载链接就好,https://developer.android.com/studio/index.html

4.Android Studio安装插件

需要安装两个插件,Flutter和Dart。打开Plugins,浏览插件市场,排第一的就是Flutter,点击安装,它会说要Dart,点确定,然后两个就都装上了,装上之后要重启Studio

5.新建Flutter项目

然后打开Studio,就会多一个 新建Flutter项目 的选项。然后我们新建一个Flutter项目

6.运行,结束

Shift+F10,项目就跑起来了

0.一些坑

当然不可能这么顺利就跑起来

我一建好项目,项目全是红的,提示找不到Flutter SDK的位置,我们自己浏览选中就好

然后 ./android/app/build.gradle 文件就报红了,原因是 Flutter 用了一个 GradleException ,这个其实默认是没有的,改成 FileNotFoundException 就不会报红了。

然后Shift+F10,提示错误,原来是要同意一大堆license。点击底部Terminal,输入

flutter doctor --android-licenses

然后一直y回车y回车y回车就可以了

然后Shift+F10跑项目,一直卡在 Running Gradle task 'assembleDebug' 半天没反应。是因为google被q了,改用国内的maven仓库就好。

有三个地方要改:
./android/build.gradle 改两个
Flutter SDK安装目录/packages/flutter_tools/gradle/flutter.gradle 改一个

repositories {
    maven { url 'https://maven.aliyun.com/repository/google' }
    maven { url 'https://maven.aliyun.com/repository/jcenter' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}

还要改flutter.gradle里面一行,换成中国的

private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";

改完之后重启Studio,打开底部Terminal,输入

flutter clean

然后重新Get dependencies,编译就快多了

然后照着新手教程敲了一遍,写了个Hello World

import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: new RandomWords(),
    );
  }
}

class RandomWordsState extends State<RandomWords> {
  final _list = <WordPair>[];
  final _like = Set<WordPair>();
  final _bigFont = new TextStyle(fontSize: 18.0);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Startup Name Generator'),
        actions: <Widget>[
          new IconButton(icon: new Icon(Icons.list), onPressed: _pushSave)
        ],
      ),
      body: _buildList(),
    );
  }

  Widget _buildList() {
    return new ListView.builder(
        padding: new EdgeInsets.all(16.0),
        itemBuilder: (context, i) {
          if (i.isOdd) {
            return new Divider();
          }
          final index = i ~/ 2;
          if (index >= _list.length) {
            _list.addAll(generateWordPairs().take(10));
          }
          return _buildRow(_list[index]);
        });
  }

  Widget _buildRow(WordPair pair) {
    final isAdd = _like.contains(pair);
    return new ListTile(
      title: new Text(
        pair.asPascalCase,
        style: _bigFont,
      ),
      trailing: new Icon(
        isAdd ? Icons.favorite : Icons.favorite_border,
        color: isAdd ? Colors.red : null,
      ),
      onTap: () {
        setState(() {
          if (isAdd) {
            _like.remove(pair);
          } else {
            _like.add(pair);
          }
        });
      },
    );
  }

  void _pushSave() {
    Navigator.of(context).push(
      new MaterialPageRoute(
        builder: (context) {
          final tiles = _like.map(
            (pair) {
              return new ListTile(
                title: new Text(
                  pair.asPascalCase,
                  style: _bigFont,
                ),
              );
            },
          );
          final divided = ListTile.divideTiles(
            context: context,
            tiles: tiles,
          ).toList();

          return new Scaffold(
            appBar: new AppBar(
              title: new Text('Saved Suggestions'),
            ),
            body: new ListView(children: divided),
          );
        },
      ),
    );
  }

}

class RandomWords extends StatefulWidget {
  @override
  State createState() {
    return new RandomWordsState();
  }
}