首页 > 其他 > 详细

Flutter基础

时间:2020-05-21 18:25:15      阅读:146      评论:0      收藏:0      [点我收藏+]

创建简单APP,主要是main.dart

import ‘package:flutter/material.dart‘;

/*void main() {
  runApp(MyApp());
}*/

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      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: new Scaffold(
        appBar: new AppBar(
          title: new Text("First Flutter Demo"),
        ),
        body: new Center(
          child: new Text("It is body"),
        ),
      ),
    );
  }
}
  • 本示例创建一个Material APP。Material是一种标准的移动端和web端的视觉设计语言。 Flutter提供了一套丰富的Material widgets。
  • main函数使用了(=>)符号, 这是Dart中单行函数或方法的简写
void main() => runApp(MyApp());   
等同于
void main() {
  runApp(MyApp());
}
  •  ^符号意味着你可以使用此插件的最新版本(大于等于当前版本)慎用
优点:能使用最新代码
缺点:编译出错,前一天代码还能编译,今天编译出错情况
  •  下划线前缀标识
final _suggestions = <WordPair>[];
在Dart语言中使用下划线前缀标识符,会强制其变成私有的。

 

Flutter基础

原文:https://www.cnblogs.com/zgz345/p/12930281.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!