你能够学到的:html
启动项目的前提是对应的xcode Android Studio环境安装彻底git
flutter doctor
安装正确会出现下面这样的提示👇:github
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-x64, locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 12.4) [✓] Android Studio (version 4.1) [✓] VS Code (version 1.52.0) [✓] Connected device (1 available) • No issues found!
若是安装错误,按照环境搭建中的安装flutterxcode
建立项目名为app的flutter项目app
flutter create app
初始化建立成功会出现下面提示less
All done! [✓] Flutter: is fully installed. (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-x64, locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 30.0.2) [✓] Xcode - develop for iOS and macOS: is fully installed. (Xcode 12.4) [✓] Android Studio: is fully installed. (version 4.1) [✓] VS Code: is fully installed. (version 1.52.0) [✓] Connected device: is fully installed. (1 available) In order to run your application, type: $ cd app $ flutter run Your application code is in app/lib/main.dart.
cd app flutter run
会自动打开模拟器,并出现下面的提示信息dom
Launching lib/main.dart on iPhone 12 Pro Max in debug mode... Running Xcode build... └─Compiling, linking and signing... 87.2s Xcode build done. 114.1s Waiting for iPhone 12 Pro Max to report its views... 4ms Syncing files to device iPhone 12 Pro Max... 353ms Flutter run key commands. r Hot reload. 🔥🔥🔥 R Hot restart. h Repeat this help message. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device). An Observatory debugger and profiler on iPhone 12 Pro Max is available at: http://127.0.0.1:55603/9Dz6pZ8WEDY=/
// 启动项目 flutter run
pubspec.yaml
文件中管理依赖,好比新增包english_words
dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.0 english_words: ^3.1.5
// 根目录命令行运行下面命令 flutter pub get
import 'package:flutter/material.dart'; import 'package:english_words/english_words.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { final wordPair = WordPair.random(); return MaterialApp( title: 'Welcome to Flutter', home: Scaffold( appBar: AppBar( title: Text('Welcome to Flutter'), ), body: Center( child: Text(wordPair.asPascalCase), ), ), ); } }
在经过flutter run
运行的命令下,输入r
便可完成热重载学习
几个常见的命令:ui
Flutter run key commands. r Hot reload. 🔥🔥🔥 R Hot restart. h Repeat this help message. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device).
经过Navigator.of来实现路由的具体实现
Navigator.of(context).push( new MaterialPageRoute<void>( builder: (BuildContext context) { }, ), );
经过onTap
来实现页面交互,使用setState改变对应状态
onTap: () { setState(() { if (alreadySaved) { _saved.remove(pair); } else { _saved.add(pair); } }); }
经过new ThemeData()
来实现主题的切换
MaterialApp( title: 'Startup Name Generator', theme: new ThemeData( primaryColor: Colors.white, ), home: RandomWords(), )