欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

使用Flutter怎么實現(xiàn)一個文本組件

本篇文章給大家分享的是有關(guān)使用Flutter怎么實現(xiàn)一個文本組件,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了富川免費建站歡迎大家使用!

?文本組件

文本組件(text)負責(zé)顯示文本和定義顯示樣式,下表為text常見屬性

Text組件屬性及描述

屬性名類型默認(rèn)值說明
dataString 要顯示的文本
maxLinesint0文本要顯示的最大行數(shù)
styleTextStylenull文本樣式,可定義文本的字體大小、顏色、粗細等
textAlignTextAlignTextAlign.center文本水平方向的對齊方式,取值有center、end、justify、left、right、start、values
textDirectionTextDirectionTextDirection.ltr文本的書寫方向,如從左到右、從右到左
textScaleFactordouble1.0字體的縮放系數(shù),比如,如果此屬性設(shè)置的值為1.5,那么字體會被放大到150%,也就是說比原來大了50%
textSpanTextSpannull文本塊,TextSpan里可以包含文本內(nèi)容及樣式

老樣子,按照慣例附上Demo,創(chuàng)建多個文本組件來展示不同的文本樣式,比如不同的顏色,不同的自號,不同的線形等。

import 'package:flutter/material.dart';
void main() => runApp(DemoApp());
class DemoApp extends StatelessWidget{
 @override
 Widget build(BuildContext context) {
 return new MaterialApp(
  title: '文本組件Demo',
  home: new Scaffold(
  appBar: new AppBar(
   title: Text('文本組件Demo'),
  ),
  body: new Column(
   children: <Widget>[
   new Text(
    '第一個文本Demo',
    style: new TextStyle(
    color: Colors.amberAccent,
    fontSize: 20,
    ),
   ),
   new Text(
    '第二個文本Demo',
    style: new TextStyle(
    color: Colors.deepOrange,
    fontSize: 20,
    ),
    textScaleFactor: 1.5,//放大50%
   ),
   new Text(
    '第三個文本Demo(瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的瞎寫的)',
    style: new TextStyle(
    color: Colors.blue,
    fontSize: 20,
    ),
    textAlign: TextAlign.end,//右對齊
   ),
   new Text(
    '''第四個文本Demo
    換到第二行,看看能不能顯示的出來呢''',
    style: new TextStyle(
    fontSize: 20,
    color: Colors.green,
    ),
    maxLines: 2,//最大顯示2行
   ),
   new Text(
    '第五個Demo,設(shè)置水平方向文案超出屏幕后,顯示...(瞎寫的字瞎寫的字瞎寫的字瞎寫的字瞎寫的字瞎寫的字瞎寫的字瞎寫的字)',
    style: new TextStyle(
    fontSize: 20,
    color: Colors.black,
    ),
    overflow: TextOverflow.ellipsis,//水平方向超出屏幕顯示...
   )
   ],
  ),//垂直方向排列
  ),
 );
 }
}

除了這些,還有很多其他的屬性等著我們?nèi)L試,我就不一一都寫出來了,我也是剛開始接觸Flutter,有些地方還不是很理解,希望以后接觸的多了,可以豁然開朗吧!!!給大家看一下效果圖:

使用Flutter怎么實現(xiàn)一個文本組件

?圖標(biāo)及按鈕組件

?圖標(biāo)組件

圖標(biāo)組件(Icon)為展示圖標(biāo)的組件,該組件不可交互,要實現(xiàn)可交互,可以考慮使用IconButton組件,圖標(biāo)組件相關(guān)的組件有一下幾個:

1.IconButton:可交互的Icon

2.Icons:框架自帶Icon集合

3.IconTheme:Icon主題

4.ImageIcon:通過AssetImages或者其他圖片顯示Icon

圖標(biāo)組件常用屬性表

屬性名類型默認(rèn)值說明
colorColornull圖標(biāo)的顏色
iconIconDatanull展示的具體圖標(biāo),可以使用Icons圖標(biāo)列表中的任意一個圖標(biāo)即可,如Icons.phone表示一個電話的圖標(biāo)
styleTextStylenull文本樣式
sizeDouble24.0圖標(biāo)的大小,注意要帶上小數(shù)位
textDirectionTextDirectionTextDirection.ltr文本排列方向

附上Demo代碼:

import 'package:flutter/material.dart';
void main() => runApp(DemoApp());
class DemoApp extends StatelessWidget{
 @override
 Widget build(BuildContext context) {
 return new MaterialApp(
  title: '圖標(biāo)組件Demo',
  home: new IconDemo(),
 );
 }
}
class IconDemo extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return new Scaffold(
  appBar: new AppBar(
  title: new Text('圖標(biāo)組件Demo'),
  ),
  body: new Center(
  child: new Icon(
   Icons.android,//圖標(biāo)Icon
   color: Colors.green,//圖標(biāo)顏色,設(shè)置為綠色,原本的顏色是黑色的
   size: 150.0,//Icon的大小
  ),
  ),
 );
 }
}

 附上效果截圖:

使用Flutter怎么實現(xiàn)一個文本組件

?圖標(biāo)按鈕組件

圖標(biāo)按鈕組件(IconButton)是基于Material Design風(fēng)格的組件,他可以響應(yīng)按下事件,并且按下時會帶一個水波紋的效果,如果它的onPressed回調(diào)函數(shù)為null,那么這個按鈕處于禁用的狀態(tài),并且不可以按下。

IconButton組件屬性及描述

屬性名類型默認(rèn)值說明
alignmentAlignmentGeometryAlignment.center定義IconButton的Icon對齊方式,默認(rèn)為居中,Alignment是可以設(shè)置x,y偏移量的
iconWidgetnull展示的具體圖標(biāo),可以使用Icons圖標(biāo)列表中的任意一個圖標(biāo)
colorColornull圖標(biāo)顏色
disabledColorColorThemeData.disableColor圖標(biāo)組件禁用的顏色
iconSizedouble24.0圖標(biāo)大小
onPressedVoidCallBacknull當(dāng)按鈕按下時會觸發(fā)此回調(diào)事件
tooltipString“”當(dāng)按鈕按下時的組件提示語

寫一個Demo,實現(xiàn)點擊IconButton,出發(fā)onPressed回調(diào)并toast一句話,附上Demo代碼:

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() => runApp(DemoApp());
class DemoApp extends StatelessWidget{
 @override
 Widget build(BuildContext context) {
 return new MaterialApp(
  debugShowCheckedModeBanner: false,
  title: 'IconButtonDemo',
  home: new IconButtonDemo(),
 );
 }
}
class IconButtonDemo extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return new Scaffold(
  appBar: AppBar(
  title: Text('IconButton Demo'),
  leading: Icon(Icons.menu),
  actions: <Widget>[
   IconButton(
   icon: Icon(Icons.search),
   )
  ],
  ),
  body: new Center(
  child: new IconButton(
   icon: Icon(Icons.add_circle_outline),
   iconSize: 50.0,
   tooltip: '用戶按下了按鈕',
   disabledColor: Colors.green,
   onPressed: (){
    Fluttertoast.showToast(
    msg: '點擊了IconButton并且Toas了一句話',
    toastLength: Toast.LENGTH_LONG,
    textColor: Colors.deepOrange,
    gravity: ToastGravity.BOTTOM
    );
  }),
  ),
 );
 }
}

 附上效果截圖:

使用Flutter怎么實現(xiàn)一個文本組件

上面的代碼除了演示了IconButton的簡單使用,還對AppBar做了一些出了,在title的左右增加了兩個圖片,當(dāng)然你也可以對其設(shè)置點擊事件

 注:這里和大家說一下在Flutter中怎么Toast出提示語,首先在pubspec.yaml引入fluttertoast包,點擊Packages get,然后在你需要toast的地方import該庫

//pubspec.yaml
fluttertoast: ^2.2.11

//import對應(yīng)庫
import 'package:fluttertoast/fluttertoast.dart';

? 凸起按鈕組件

突起按鈕組件(RaisedButton),往往我們在開發(fā)過程中,不會一直用系統(tǒng)的圖標(biāo),那么如果一個按鈕上需要我們添加自定義的文本,這樣的按鈕要怎么實現(xiàn)呢?

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() => runApp(DemoApp());
class DemoApp extends StatelessWidget{
 @override
 Widget build(BuildContext context) {
 return new MaterialApp(
  debugShowCheckedModeBanner: false,
  title: 'IconButtonDemo',
  home: new IconButtonDemo(),
 );
 }
}
class IconButtonDemo extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return new Scaffold(
  appBar: AppBar(
  title: Text('IconButton Demo'),
  leading: Icon(Icons.menu),
  actions: <Widget>[
   IconButton(
   icon: Icon(Icons.search),
   )
  ],
  ),
  body: new Center(
  child: new RaisedButton(
   padding: const EdgeInsets.all(10.0),//內(nèi)間距
   splashColor: Colors.blue,//點擊時按鈕的顏色
   elevation: 10,
   shape: BeveledRectangleBorder(//帶斜角的長方形邊框
   borderRadius: BorderRadius.all(Radius.circular(5))//圓角
   ),
   onPressed: (){
   Fluttertoast.showToast(
    msg: '點擊了IconButton并且Toas了一句話',
    toastLength: Toast.LENGTH_LONG,
    textColor: Colors.deepOrange,
    gravity: ToastGravity.BOTTOM
   );
   },
   //按鈕內(nèi)的文本
   child: new Text(
   '我是RaisedButton按鈕',
   style: TextStyle(
    color: Colors.green,
    fontSize: 20.0,
   ),
   ),
  ),
  ),
 );
 }
}

以上就是使用Flutter怎么實現(xiàn)一個文本組件,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

本文名稱:使用Flutter怎么實現(xiàn)一個文本組件
分享URL:http://www.chinadenli.net/article48/peeghp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊品牌網(wǎng)站制作網(wǎng)站維護營銷型網(wǎng)站建設(shè)手機網(wǎng)站建設(shè)ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化