flutter widget

Demo

import 'package:flutter/material.dart';

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

var name = 'k';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
      return new MaterialApp(
          title: "title",
          theme: ThemeData.light(), //背景主題色
          debugShowCheckedModeBanner: false, //消除界面右上角debug標(biāo)簽
          home: new Scaffold(
          body: new Text(
              "data $name", //變量引用塌碌,以$開頭:$variablity
              textAlign: TextAlign.center,
              overflow: TextOverflow.clip, //clip:折疊; ellipsis:省略號; fade:淡出
              textScaleFactor: 3, //放大比率
              style: TextStyle(
              fontWeight: FontWeight.bold,
              fontFamily: "arial",
              height: 2, //行高
              decoration: TextDecoration.underline, //文本裝飾類型
              decorationColor: Colors.red, //文本裝飾顏色
              decorationStyle: TextDecorationStyle.dashed, //文本裝飾樣式
              ),
          ),
          ),
      );
  }
}
  • Scaffold
(new) Scaffold({
  Key key,
  PreferredSizeWidget appBar,
  Widget body,
  Widget floatingActionButton,
  FloatingActionButtonLocation floatingActionButtonLocation,
  FloatingActionButtonAnimator floatingActionButtonAnimator,
  List<Widget> persistentFooterButtons,
  Widget drawer,
  Widget endDrawer,
  Widget bottomNavigationBar,
  Widget bottomSheet,
  Color backgroundColor,
  bool resizeToAvoidBottomPadding,
  bool resizeToAvoidBottomInset,
  bool primary: true,
  DragStartBehavior drawerDragStartBehavior: DragStartBehavior.start,
  bool extendBody: false
}) → Scaffold

Basic widgets

Container

(new) Container({
  Key key,
  AlignmentGeometry alignment,//浮動對齊
  EdgeInsetsGeometry padding,//內(nèi)邊距
  Color color,//背景色
  Decoration decoration,//child后的樣式
  Decoration foregroundDecoration,//child前的樣式
  double width,
  double height,
  BoxConstraints constraints,
  EdgeInsetsGeometry margin,//外邊距
  Matrix4 transform,//旋轉(zhuǎn)
  Widget child//子類
}) → Container

Row

(new) Row({
Key key,
MainAxisAlignment mainAxisAlignment: MainAxisAlignment.start,//橫向?qū)R方式
MainAxisSize mainAxisSize: MainAxisSize.max,//橫向軸最大尺寸
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,//豎直位置
TextDirection textDirection,//文字方向
VerticalDirection verticalDirection: VerticalDirection.down,//豎直方向
TextBaseline textBaseline,//文字基準(zhǔn)線
List<Widget> children: const <Widget> []//子類(數(shù)組)
}) → Row

Column

(new) Column({
Key key,
MainAxisAlignment mainAxisAlignment: MainAxisAlignment.start,//橫向?qū)R方式
MainAxisSize mainAxisSize: MainAxisSize.max,//橫向軸最大尺寸
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,//豎直位置
TextDirection textDirection,//文字方向
VerticalDirection verticalDirection: VerticalDirection.down,//豎直方向
TextBaseline textBaseline,//文字基準(zhǔn)線
List<Widget> children: const <Widget> []//子類(數(shù)組)
}) → Column

Image

Image.asset //加載資源圖片互捌,就是加載項目資源目錄中的圖片,加入圖片后會增大打包的包體體積,用的是相對路徑
Image.network //網(wǎng)絡(luò)資源圖片蚌铜,意思就是你需要加入一段http://xxxx.xxx的這樣的網(wǎng)絡(luò)路徑地址
Image.file //加載本地圖片暂刘,就是加載本地文件中的圖片饺谬,這個是一個絕對路徑,跟包體無關(guān)【不常用】
Image.memory //加載Uint8List資源圖片【不常用】

//——————————————————————
//attribute
image: AssetImage(String assetName, {AssetBundle bundle, String package}) → AssetImage

image: NetworkImage(String url, {double scale: 1.0, Map<String, String> headers}) → NetworkImage

Text

Text(String data,{ //文字字符串
Key key,
TextStyle style, //文字樣式
StrutStyle strutStyle,
TextAlign textAlign, //對齊方式
TextDirection textDirection, //文字裝飾
Locale locale,
bool softWrap,
TextOverflow overflow, //溢出顯示
double textScaleFactor, //縮放比例
int maxLines, //最大行數(shù)
String semanticsLabel
}) → Text

Icon

Icon(IconData icon, { 
Key key,
double size, //尺寸谣拣,默認(rèn)24px
Color color, //主題色
String semanticLabel, //語義標(biāo)簽募寨,供殘障用戶使用
TextDirection textDirection //渲染圖標(biāo)方向,需要IconData.matchTextDirection字段為true
}) → Icon

//extensions
IconButton({
Key key,
double iconSize: 24.0,
EdgeInsetsGeometry padding: const EdgeInsets.all(8.0),
AlignmentGeometry alignment: Alignment.center,
Widget icon,
Color color,
Color highlightColor, //按鈕處于向下(按下)狀態(tài)時按鈕的輔助顏色
Color splashColor, //按鈕處于向下(按下)狀態(tài)時按鈕的主要顏色
Color disabledColor,
() → void onPressed, //點擊回調(diào)函數(shù)
String tooltip //輔助文字說明標(biāo)簽
}) → IconButton

Icons //引用flutter內(nèi)置圖標(biāo)

IconTheme({
Key key,
IconThemeData data,//IconThemeData({Color color, double opacity, double size}) → IconThemeData
Widget child //Icon和ImageIcon應(yīng)用IconThemeData中定義的主題屬性
}) → IconTheme

ImageIcon(ImageProvider<dynamic> image,{
Key key,
double size,
Color color,
String semanticLabel
}) → ImageIcon

FlatButton 背景透明按鈕

FloatingActionButton 浮動按鈕

IconButton 圖標(biāo)按鈕

PopupMenuButton 下拉菜單按鈕

RaisedButton

(new) RaisedButton({
Key key,
() → void onPressed,
(bool) → void onHighlightChanged,
ButtonTextTheme textTheme,
Color textColor,
Color disabledTextColor,
Color color,
Color disabledColor,
Color highlightColor, //按鈕處于向下(按下)狀態(tài)時按鈕的輔助顏色
Color splashColor, //按鈕處于向下(按下)狀態(tài)時按鈕的主要顏色
Brightness colorBrightness,
double elevation,
double highlightElevation,
double disabledElevation,
EdgeInsetsGeometry padding,
ShapeBorder shape,
Clip clipBehavior: Clip.none,
MaterialTapTargetSize materialTapTargetSize,
Duration animationDuration,
Widget child
}) → RaisedButton

AppBar

(new) AppBar({
  Key key,
  Widget leading, //標(biāo)題上方widget
  bool automaticallyImplyLeading: true,
  Widget title,
  List<Widget> actions, //標(biāo)題下方功能按鈕組
  Widget flexibleSpace,
  PreferredSizeWidget bottom,
  double elevation,
  Color backgroundColor,
  Brightness brightness,//亮度
  IconThemeData iconTheme,
  TextTheme textTheme,
  bool primary: true,
  bool centerTitle, //標(biāo)題是否居中
  double titleSpacing: NavigationToolbar.kMiddleSpacing,
  double toolbarOpacity: 1.0, //工具欄透明度
  double bottomOpacity: 1.0 //底部透明度
}) → AppBar

Theme

ThemeData

(new) ThemeData({
  Brightness brightness,
  MaterialColor primarySwatch,
  Color primaryColor,
  Brightness primaryColorBrightness,
  Color primaryColorLight,
  Color primaryColorDark,
  Color accentColor,
  Brightness accentColorBrightness,
  Color canvasColor,
  Color scaffoldBackgroundColor,
  Color bottomAppBarColor,
  Color cardColor,
  Color dividerColor,
  Color highlightColor,
  Color splashColor,
  InteractiveInkFeatureFactory splashFactory,
  Color selectedRowColor,
  Color unselectedWidgetColor,
  Color disabledColor,
  Color buttonColor,
  ButtonThemeData buttonTheme,
  Color secondaryHeaderColor,
  Color textSelectionColor,
  Color cursorColor,
  Color textSelectionHandleColor,
  Color backgroundColor,
  Color dialogBackgroundColor,
  Color indicatorColor,
  Color hintColor,
  Color errorColor,
  Color toggleableActiveColor,
  String fontFamily,
  TextTheme textTheme,
  TextTheme primaryTextTheme,
  TextTheme accentTextTheme,
  InputDecorationTheme inputDecorationTheme,
  IconThemeData iconTheme,
  IconThemeData primaryIconTheme,
  IconThemeData accentIconTheme,
  SliderThemeData sliderTheme,
  TabBarTheme tabBarTheme,
  CardTheme cardTheme,
  ChipThemeData chipTheme,
  TargetPlatform platform,
  MaterialTapTargetSize materialTapTargetSize,
  PageTransitionsTheme pageTransitionsTheme,
  AppBarTheme appBarTheme,
  BottomAppBarTheme bottomAppBarTheme,
  ColorScheme colorScheme,
  DialogTheme dialogTheme,
  Typography typography,
  CupertinoThemeData cupertinoOverrideTheme
}) → ThemeData

Layout

Basic layout

Container

//as above

Padding

Padding({Key key, EdgeInsetsGeometry padding, Widget child}) → Padding

Center

Center({Key key, double widthFactor, double heightFactor, Widget child}) → Center

Align

Align({Key key, AlignmentGeometry alignment: Alignment.center, double widthFactor, double heightFactor, Widget child}) → Align

FittedBox 內(nèi)部元素大小隨動變化

FittedBox({Key key, BoxFit fit: BoxFit.contain, AlignmentGeometry alignment: Alignment.center, Widget child}) → FittedBox

AspectRatio 定長寬比widget

AspectRatio({Key key, double aspectRatio, Widget child}) → AspectRatio

ConstrainedBox 約束內(nèi)部元素widget

ConstrainedBox({Key key, BoxConstraints constraints, Widget child}) → ConstrainedBox

IntrinsicHeight 子元素?fù)螡M高度

IntrinsicHeight({Key key, Widget child}) → IntrinsicHeight

IntrinsicWidth 子元素?fù)螡M寬度

IntrinsicWidth({Key key, double stepWidth, double stepHeight, Widget child}) → IntrinsicWidth
Complex layout

Row

//as above

Column

//as above

Stack 允許堆疊

Stack({Key key, AlignmentGeometry alignment: AlignmentDirectional.topStart, TextDirection textDirection, StackFit fit: StackFit.loose, Overflow overflow: Overflow.clip, List<Widget> children: const <Widget> []}) → Stack

Flow

Flow({Key key, FlowDelegate delegate, List<Widget> children: const <Widget> []}) → Flow

Table

Table({Key key, List<TableRow> children: const <TableRow> [], Map<int, TableColumnWidth> columnWidths, TableColumnWidth defaultColumnWidth: const FlexColumnWidth(1.0), TextDirection textDirection, TableBorder border, TableCellVerticalAlignment defaultVerticalAlignment: TableCellVerticalAlignment.top, TextBaseline textBaseline}) → Table

Wrap

Wrap({Key key, Axis direction: Axis.horizontal, WrapAlignment alignment: WrapAlignment.start, double spacing: 0.0, WrapAlignment runAlignment: WrapAlignment.start, double runSpacing: 0.0, WrapCrossAlignment crossAxisAlignment: WrapCrossAlignment.start, TextDirection textDirection, VerticalDirection verticalDirection: VerticalDirection.down, List<Widget> children: const <Widget> []}) → Wrap

ListBody

ListBody({Key key, Axis mainAxis: Axis.vertical, bool reverse: false, List<Widget> children: const <Widget> []}) → ListBody

ListView

ListView({Key key, Axis scrollDirection: Axis.vertical, bool reverse: false, ScrollController controller, bool primary, ScrollPhysics physics, bool shrinkWrap: false, EdgeInsetsGeometry padding, double itemExtent, bool addAutomaticKeepAlives: true, bool addRepaintBoundaries: true, bool addSemanticIndexes: true, double cacheExtent, List<Widget> children: const <Widget> [], int semanticChildCount, DragStartBehavior dragStartBehavior: DragStartBehavior.down}) → ListView

Transitions

FadeTransition

(new) FadeTransition({Key key, Animation<double> opacity, bool alwaysIncludeSemantics: false, Widget child}) → FadeTransition

SizeTransition

(new) SizeTransition({Key key, Axis axis: Axis.vertical, Animation<double> sizeFactor, double axisAlignment: 0.0, Widget child}) → SizeTransition

AlignTransition

(new) AlignTransition({Key key, Animation<AlignmentGeometry> alignment, Widget child, double widthFactor, double heightFactor}) → AlignTransition

ScaleTransition

(new) ScaleTransition({Key key, Animation<double> scale, Alignment alignment: Alignment.center, Widget child}) → ScaleTransition

SlideTransition

(new) SlideTransition({Key key, Animation<Offset> position, bool transformHitTests: true, TextDirection textDirection, Widget child}) → SlideTransition

RotationTransition

(new) RotationTransition({Key key, Animation<double> turns, Alignment alignment: Alignment.center, Widget child}) → RotationTransition

PositionedTransition

(new) PositionedTransition({Key key, Animation<RelativeRect> rect, Widget child}) → PositionedTransition

Tween

(new) Tween({double begin}, {double end}) → Tween<double>

Duration

(new) Duration({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, int milliseconds: 0, int microseconds: 0}) → Duration

AnimationController

(new) AnimationController({double value, Duration duration, String debugLabel, double lowerBound: 0.0, double upperBound: 1.0, AnimationBehavior animationBehavior: AnimationBehavior.normal, TickerProvider vsync}) → AnimationController

Debounce function

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  Duration durationTime = Duration(milliseconds: 300);
  Timer timer;
  
  submit() {
    timer?.cancel();
    timer = new Timer(durationTime, () {
      // ...
    })
  }
  // ...
}

Localstorage

Import shared_preferences flutter package

// package localstorage handler function
import 'package:shared_preferences/shared_preferences.dart';

class LocalStorage {
  static LocalStorage _instance;
  
  static Future<LocalStorage> get instance async {
    return await getInstance();
  }

  static SharedPreferences _prefs;

  LocalStorage._();

  Future _init() async {
    _prefs = await SharedPreferences.getInstance();
  }

  static Future<LocalStorage> getInstance() async  {
    if (_instance == null) {
      _instance = new LocalStorage._();
      await _instance._init();

    }
    return _instance;
  }

  static bool _beforeCheck() {
    if (_prefs == null) {
      return true;
    }
    return false;
  }

  getItem(String key) {
    if (_beforeCheck()) return null;
    return _prefs.getString(key);
  }

  Future<bool> setItem(String key, String value) {
    if (_beforeCheck()) return null;
    return _prefs.setString(key, value);
  }
  
  remomve(String key) {
    if (_beforeCheck()) return null;
    return _prefs.remove(key);
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末森缠,一起剝皮案震驚了整個濱河市拔鹰,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌贵涵,老刑警劉巖列肢,帶你破解...
    沈念sama閱讀 221,198評論 6 514
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異宾茂,居然都是意外死亡瓷马,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,334評論 3 398
  • 文/潘曉璐 我一進(jìn)店門跨晴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來决采,“玉大人,你說我怎么就攤上這事坟奥∈鞑t!?“怎么了?”我有些...
    開封第一講書人閱讀 167,643評論 0 360
  • 文/不壞的土叔 我叫張陵爱谁,是天一觀的道長晒喷。 經(jīng)常有香客問我,道長访敌,這世上最難降的妖魔是什么凉敲? 我笑而不...
    開封第一講書人閱讀 59,495評論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮寺旺,結(jié)果婚禮上爷抓,老公的妹妹穿的比我還像新娘。我一直安慰自己阻塑,他們只是感情好蓝撇,可當(dāng)我...
    茶點故事閱讀 68,502評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著陈莽,像睡著了一般渤昌。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上走搁,一...
    開封第一講書人閱讀 52,156評論 1 308
  • 那天独柑,我揣著相機(jī)與錄音,去河邊找鬼私植。 笑死忌栅,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的曲稼。 我是一名探鬼主播索绪,決...
    沈念sama閱讀 40,743評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼躯肌!你這毒婦竟也來了者春?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,659評論 0 276
  • 序言:老撾萬榮一對情侶失蹤清女,失蹤者是張志新(化名)和其女友劉穎钱烟,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體嫡丙,經(jīng)...
    沈念sama閱讀 46,200評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡拴袭,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,282評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了曙博。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片拥刻。...
    茶點故事閱讀 40,424評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖父泳,靈堂內(nèi)的尸體忽然破棺而出般哼,到底是詐尸還是另有隱情吴汪,我是刑警寧澤,帶...
    沈念sama閱讀 36,107評論 5 349
  • 正文 年R本政府宣布蒸眠,位于F島的核電站漾橙,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏楞卡。R本人自食惡果不足惜霜运,卻給世界環(huán)境...
    茶點故事閱讀 41,789評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望蒋腮。 院中可真熱鬧淘捡,春花似錦、人聲如沸池摧。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,264評論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽险绘。三九已至踢京,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間宦棺,已是汗流浹背瓣距。 一陣腳步聲響...
    開封第一講書人閱讀 33,390評論 1 271
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留代咸,地道東北人蹈丸。 一個月前我還...
    沈念sama閱讀 48,798評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像呐芥,于是被迫代替她去往敵國和親逻杖。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,435評論 2 359

推薦閱讀更多精彩內(nèi)容