新聞中心
這是一個(gè)跨端的時(shí)代,各種跨端框架你方唱罷我登場,今天小編帶領(lǐng)大家來入門Flutter,看它到底有沒有傳說中的那么好。磨刀不誤砍柴工,先來安裝Flutter開發(fā)環(huán)境吧。先安裝Android Studio,然后在Settings->Plugin里選擇 Browser Repositories,在線安裝Flutter插件。安裝Flutter插件時(shí),它會(huì)提示自動(dòng)安裝Dart語言插件。

成都創(chuàng)新互聯(lián)成立于2013年,先為巴彥等服務(wù)建站,巴彥等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為巴彥企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
安裝插件
插件安裝好后,需要再去Flutter中文官網(wǎng)下載SDK(比英文官網(wǎng)下載速度快很多),根據(jù)官網(wǎng)要求設(shè)置好Flutter Path及Git Path的系統(tǒng)環(huán)境變量。然后在命令行窗口輸入flutter doctor命令,它會(huì)自動(dòng)關(guān)聯(lián)下載Dart SDK,如果發(fā)現(xiàn)下載比較慢,可以將FLUTTER_STORAGE_BASE_URL和PUB_HOSTED_URL兩個(gè)網(wǎng)址映射到中文站,并添加到系統(tǒng)環(huán)境變量里。flutter doctor多次運(yùn)行后,會(huì)看到提示小編的android studio版本太低(我的是2.3版本,而flutter要求3.0版本以上),倒霉了,得升級(jí)android studio,差不多1個(gè)G,可夠我下載的了,先去泡杯咖啡,再繼續(xù)。
flutter doctor命令
檢查結(jié)果
新版android studio安裝好后,按照最開始的步驟,在settings->plugins菜單里安裝flutter 和 dart插件,然后就可以在File菜單開始New一個(gè)flutter的Project啦!
new flutter project
工程建好后,我們可以看到 flutter app的代碼是用Dart語言編寫的,語法與Java非常類似,幾乎沒有什么新的學(xué)習(xí)成本。從MyApp的代碼來看,我們可以知道flutter里的界面都是用Widget來搭建的,這一點(diǎn)與Android不同,后面小編再帶大家細(xì)細(xì)品味Widget。
- import 'package:flutter/material.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- // This is the theme of your application.
- //
- // Try running your application with "flutter run". You'll see the
- // application has a blue toolbar. Then, without quitting the app, try
- // changing the primarySwatch below to Colors.green and then invoke
- // "hot reload" (press "r" in the console where you ran "flutter run",
- // or simply save your changes to "hot reload" in a Flutter IDE).
- // Notice that the counter didn't reset back to zero; the application
- // is not restarted.
- primarySwatch: Colors.blue,
- // This makes the visual density adapt to the platform that you run
- // the app on. For desktop platforms, the controls will be smaller and
- // closer together (more dense) than on mobile platforms.
- visualDensity: VisualDensity.adaptivePlatformDensity,
- ),
- home: MyHomePage(title: 'Flutter Hello World!'),
- );
- }
- }
運(yùn)行后,我們?cè)诎沧磕M器里可以看到flutter程序順利的跑在了android系統(tǒng)里了,無需做任何android的代碼移植,天生支持android。當(dāng)然它也天生支持iOS,這就是我們第一個(gè)跨端app!
分享名稱:Flutter入門,寫一個(gè)跨平臺(tái)的HelloWorld
網(wǎng)頁URL:http://m.fisionsoft.com.cn/article/cdggcij.html


咨詢
建站咨詢
