亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Flutter懸浮按鈕FloatingActionButton使用詳解

 更新時(shí)間:2021年07月12日 10:42:15   作者:sugood  
本文主要介紹了Flutter懸浮按鈕FloatingActionButton使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1、普通用法

floatingActionButton: FloatingActionButton(
    child: Icon(Icons.add),
      onPressed: (){
         print('不要啊~');
      },
 ),

2、修改懸浮按鈕位置

繼承FloatingActionButtonLocation類,重寫對(duì)應(yīng)方法自定義位置

import 'package:flutter/material.dart';

class CustomFloatingActionButtonLocation extends FloatingActionButtonLocation {
  FloatingActionButtonLocation location;
  double offsetX;    // X方向的偏移量
  double offsetY;    // Y方向的偏移量
  CustomFloatingActionButtonLocation(this.location, this.offsetX, this.offsetY);

  @override
  Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
    Offset offset = location.getOffset(scaffoldGeometry);
    return Offset(offset.dx + offsetX, offset.dy + offsetY);
  }
}

使用

floatingActionButtonLocation:CustomFloatingActionButtonLocation(
             FloatingActionButtonLocation.endFloat, 0, -DpUtils.setWidth(20)),

3、修改懸浮按鈕大小

floatingActionButton: SizedBox(
  height: 100.0,
  width: 100.0,
  child:FloatingActionButton(
    child: Icon(Icons.add),
    onPressed: () {},
  ),
),

4、去除懸浮按鈕切換動(dòng)畫

繼承FloatingActionButtonAnimator類并重寫對(duì)應(yīng)的方法

import 'package:flutter/material.dart';

class NoScalingAnimation extends FloatingActionButtonAnimator{
  double _x;
  double _y;
  @override
  Offset getOffset({Offset begin, Offset end, double progress}) {
    _x = begin.dx +(end.dx - begin.dx)*progress ;
    _y = begin.dy +(end.dy - begin.dy)*progress;
    return Offset(_x,_y);
  }

  @override
  Animation<double> getRotationAnimation({Animation<double> parent}) {
    return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  }

  @override
  Animation<double> getScaleAnimation({Animation<double> parent}) {
    return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  }
}

使用

floatingActionButtonAnimator: NoScalingAnimation(),

5、一般的自定義懸浮按鈕樣式

@override
  Widget build(BuildContext context) {
    return Scaffold(
       floatingActionButton: FloatingActionButton(
          child: Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Image.asset(
                  "images/float_button.png",
                  width: DpUtils.setWidth(32),
                  height: DpUtils.setWidth(32),
                ),
                Text(
                  "懸浮按鈕",
                  style: TextStyle(fontWeight: FontWeight.bold, 
                        fontSize: DpUtils.setSp(20), color: Colors.white),
                ),
              ],
            ),
          ),
          elevation: 0,
          onPressed: () {
            _doSome();
          },
          backgroundColor: Colors.black,
          heroTag: "floatHome",
        ),
    )
)}

6、徹底的自定義懸浮按鈕樣式

其實(shí),floatingActionButton 可以直接傳入普通的widget。所以該干嘛干嘛咯

@override
  Widget build(BuildContext context) {
    return Scaffold(
        floatingActionButton: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Image.asset(
                "images/home_icon_publishing.png",
                width: DpUtils.setWidth(32),
                height: DpUtils.setWidth(32),
              ),
              Text(
                "發(fā)主題",
                style: TextStyle(fontWeight: FontWeight.bold, 
                     fontSize: DpUtils.setSp(20), color: Colors.white),
              ),
            ],
          ),
        ),
    );
  }

到此這篇關(guān)于Flutter懸浮按鈕FloatingActionButton使用詳解的文章就介紹到這了,更多相關(guān)Flutter懸浮按鈕FloatingActionButton內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Android切面編程入門講解

    Android切面編程入門講解

    這篇文章給大家分享了關(guān)于Android進(jìn)階資深開發(fā)必備技能-切面編程入門的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們參考下。
    2018-08-08
  • 詳解Android MacAddress 適配心得

    詳解Android MacAddress 適配心得

    本篇文章主要介紹了詳解Android MacAddress 適配心得,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • Android下載gradle失敗的解決方法

    Android下載gradle失敗的解決方法

    這篇文章主要介紹了Android下載gradle失敗的解決方法,文章通過圖文結(jié)合的方式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-06-06
  • Android NavigationBar問題處理的方法

    Android NavigationBar問題處理的方法

    本篇文章主要介紹了Android NavigationBar問題處理的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-10-10
  • Android?NotificationListenerService通知監(jiān)聽服務(wù)使用

    Android?NotificationListenerService通知監(jiān)聽服務(wù)使用

    這篇文章主要為大家介紹了Android?NotificationListenerService通知監(jiān)聽服務(wù)使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Android中使用sax解析xml文件的方法

    Android中使用sax解析xml文件的方法

    本篇文章介紹了,在Android中使用sax解析xml文件的方法。需要的朋友參考下
    2013-04-04
  • Android權(quán)限如何禁止以及友好提示用戶開通必要權(quán)限詳解

    Android權(quán)限如何禁止以及友好提示用戶開通必要權(quán)限詳解

    這篇文章主要給大家介紹了關(guān)于Android權(quán)限如何禁止以及友好提示用戶開通必要權(quán)限的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • android H5本地緩存加載優(yōu)化的實(shí)戰(zhàn)

    android H5本地緩存加載優(yōu)化的實(shí)戰(zhàn)

    這篇文章主要介紹了android H5本地緩存加載優(yōu)化的實(shí)戰(zhàn),幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-04-04
  • 談一談Android內(nèi)存泄漏問題

    談一談Android內(nèi)存泄漏問題

    談一談Android內(nèi)存泄漏問題,圍繞內(nèi)存泄露的定義、內(nèi)存泄露的原理、內(nèi)存泄露的解決方法進(jìn)行探討,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android圖片實(shí)現(xiàn)壓縮處理的實(shí)例代碼

    Android圖片實(shí)現(xiàn)壓縮處理的實(shí)例代碼

    本篇文章主要介紹了Android圖片實(shí)現(xiàn)壓縮處理的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07

最新評(píng)論