淺嘗flutter中的動畫(淡入淡出)

在移動端開發中,經常會有一些動畫交互,比如淡入淡出,效果如圖:

因為官方封裝好了AnimatedOpacity Widget,開箱即用,所以我們用起來很方便,代碼量很少,做少量配置即可,所以,全部代碼如下:

import 'package:flutter/material.dart';class TabPage3 extends StatefulWidget {@overridecreateState() => new LogoFadeState();
}
class LogoFadeState extends State<TabPage3> {// 初始opacityLevel為1.0為可見狀態,為0.0時不可見double opacityLevel = 1.0;_changeOpacity() {//調用setState()  根據opacityLevel當前的值重繪ui// 當用戶點擊按鈕時opacityLevel的值會(1.0=>0.0=>1.0=>0.0 ...)切換// 所以AnimatedOpacity 會根據opacity傳入的值(opacityLevel)進行重繪 WidgetsetState(() => opacityLevel = opacityLevel == 0 ? 1.0 : 0.0);}@overrideWidget build(BuildContext context) {return new Column(//一個Column布局,主軸為垂直方向,起點在上沿。mainAxisAlignment: MainAxisAlignment.spaceAround,//子組件在主軸上均勻分布在容器內,兩邊留有一半的間隔空間。children: [new AnimatedOpacity(// 使用一個AnimatedOpacity Widgetopacity: opacityLevel,duration: new Duration(seconds: 1),//過渡時間:1child:new Container(padding:const EdgeInsets.only(right:20.0,bottom:15.0,left:20.0),//內邊距child:new Text("和React Native一樣,Flutter也提供響應式的視圖,Flutter采用不同的方法避免由JavaScript橋接器引起的性能問題,即用名為Dart的程序語言來編譯。Dart是用預編譯的方式編譯多個平臺的原生代碼,這允許Flutter直接與平臺通信,而不需要通過執行上下文切換的JavaScript橋接器。編譯為原生代碼也可以加快應用程序的啟動時間。實際上,Flutter是唯一提供響應式視圖而不需要JavaScript橋接器的移動SDK,這就足以讓Fluttter變得有趣而值得一試,但Flutter還有一些革命性的東西,即它是如何實現UI組件的?") ,)),new RaisedButton(child:new Container(child: new Text("點我試試"),) ,onPressed: _changeOpacity,//添加點擊事件),],);}
}復制代碼

flutter官方給我們封裝了很多很多常用的開箱即用的控件,為開發帶來了極大的便利。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390736.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390736.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390736.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

數據科學還是計算機科學_何時不使用數據科學

數據科學還是計算機科學意見 (Opinion) 目錄 (Table of Contents) Introduction 介紹 Examples 例子 When You Should Use Data Science 什么時候應該使用數據科學 Summary 摘要 介紹 (Introduction) Both Data Science and Machine Learning are useful fields that apply sev…

空間復雜度 用什么符號表示_什么是大O符號解釋:時空復雜性

空間復雜度 用什么符號表示Do you really understand Big O? If so, then this will refresh your understanding before an interview. If not, don’t worry — come and join us for some endeavors in computer science.您真的了解Big O嗎&#xff1f; 如果是這樣&#xf…

leetcode 523. 連續的子數組和

給你一個整數數組 nums 和一個整數 k &#xff0c;編寫一個函數來判斷該數組是否含有同時滿足下述條件的連續子數組&#xff1a; 子數組大小 至少為 2 &#xff0c;且 子數組元素總和為 k 的倍數。 如果存在&#xff0c;返回 true &#xff1b;否則&#xff0c;返回 false 。 …

Docker學習筆記 - Docker Compose

一、概念 Docker Compose 用于定義運行使用多個容器的應用&#xff0c;可以一條命令啟動應用&#xff08;多個容器&#xff09;。 使用Docker Compose 的步驟&#xff1a; 定義容器 Dockerfile定義應用的各個服務 docker-compose.yml啟動應用 docker-compose up二、安裝 Note t…

創建shell腳本

1.寫一個腳本 a) 用touch命令創建一個文件&#xff1a;touch my_script b) 用vim編輯器打開my_script文件&#xff1a;vi my_script c) 用vim編輯器編輯my_script文件,內容如下&#xff1a; #!/bin/bash 告訴shell使用什么程序解釋腳本 #My first script l…

線性回歸算法數學原理_線性回歸算法-非數學家的高級數學

線性回歸算法數學原理內部AI (Inside AI) Linear regression is one of the most popular algorithms used in different fields well before the advent of computers. Today with the powerful computers, we can solve multi-dimensional linear regression which was not p…

您應該在2020年首先學習哪種編程語言? ????d???s????:???su?

Most people’s journey toward learning to program starts with a single late-night Google search.大多數人學習編程的旅程都是從一個深夜Google搜索開始的。 Usually it’s something like “Learn ______”通常它類似于“學習______” But how do they decide which la…

Linux 概述

UNIX發展歷程 第一個版本是1969年由Ken Thompson&#xff08;UNIX之父&#xff09;在AT& T貝爾實驗室實現Ken Thompson和Dennis Ritchie&#xff08;C語言之父&#xff09;使用C語言對整個系統進行了再加工和編寫UNIX的源代碼屬于SCO公司&#xff08;AT&T ->Novell …

課程一(Neural Networks and Deep Learning),第四周(Deep Neural Networks)—— 0.學習目標...

Understand the key computations underlying deep learning, use them to build and train deep neural networks, and apply it to computer vision. 學習目標 See deep neural networks as successive blocks put one after each otherBuild and train a deep L-layer Neura…

使用ActionTrail Python SDK

ActionTrail提供官方的Python SDK。本文將簡單介紹一下如何使用ActionTrail的Python SDK。 安裝Aliyun Core SDK。 pip install aliyun-python-sdk-core 安裝ActionTrail Python SDK。 pip install aliyun-python-sdk-actiontrail 下面是測試的代碼。調用LookupEventsRequest獲…

泰坦尼克:機器從災難中學習_用于災難響應的機器學習研究:什么才是好的論文?...

泰坦尼克:機器從災難中學習For the first time in 2021, a major Machine Learning conference will have a track devoted to disaster response. The 16th Conference of the European Chapter of the Association for Computational Linguistics (EACL 2021) has a track on…

github持續集成的設置_如何使用GitHub Actions和Puppeteer建立持續集成管道

github持續集成的設置Lately Ive added continuous integration to my blog using Puppeteer for end to end testing. My main goal was to allow automatic dependency updates using Dependabot. In this guide Ill show you how to create such a pipeline yourself. 最近&…

shell與常用命令

虛擬控制臺 一臺計算機的輸入輸出設備就是一個物理的控制臺 &#xff1b; 如果在一臺計算機上用軟件的方法實現了多個互不干擾獨立工作的控制臺界面&#xff0c;就是實現了多個虛擬控制臺&#xff1b; Linux終端的工作方式是字符命令行方式&#xff0c;用戶通過鍵盤輸入命令進…

C中的malloc:C中的動態內存分配

什么是C中的malloc()&#xff1f; (What is malloc() in C?) malloc() is a library function that allows C to allocate memory dynamically from the heap. The heap is an area of memory where something is stored.malloc()是一個庫函數&#xff0c;它允許C從堆動態分配…

Linux文本編輯器

Linux文本編輯器 Linux系統下有很多文本編輯器。 按編輯區域&#xff1a; 行編輯器 ed 全屏編輯器 vi 按運行環境&#xff1a; 命令行控制臺編輯器 vi X Window圖形界面編輯器 gedit ed 它是一個很古老的行編輯器&#xff0c;vi這些編輯器都是ed演化而來。 每次只能對一…

Alpha第十天

Alpha第十天 聽說 031502543 周龍榮&#xff08;隊長&#xff09; 031502615 李家鵬 031502632 伍晨薇 031502637 張檉 031502639 鄭秦 1.前言 任務分配是VV、ZQ、ZC負責前端開發&#xff0c;由JP和LL負責建庫和服務器。界面開發的教輔材料是《第一行代碼》&#xff0c;利用And…

Streamlit —使用數據應用程序更好地測試模型

介紹 (Introduction) We use all kinds of techniques from creating a very reliable validation set to using k-fold cross-validation or coming up with all sorts of fancy metrics to determine how good our model performs. However, nothing beats looking at the ra…

Spring MVC Boot Cloud 技術教程匯總(長期更新)

昨天我們發布了Java成神之路上的知識匯總&#xff0c;今天繼續。 Java成神之路技術整理&#xff08;長期更新&#xff09; 以下是Java技術棧微信公眾號發布的關于 Spring/ Spring MVC/ Spring Boot/ Spring Cloud 的技術干貨&#xff0c;本文長期更新。 Spring 系列 Java 必看的…

X Window系統

X Window系統 一種以位圖方式顯示的軟件窗口系統。誕生于1984&#xff0c;比Microsoft Windows要早。是一套獨立于內核的軟件 Linux上的X Window系統 X Window系統由三個基本元素組成&#xff1a;X Server、X Client和二者通信的通道。 X Server&#xff1a;是控制輸出及輸入…

冒名頂替上大學羅彩霞_什么是冒名頂替綜合癥,您如何克服?

冒名頂替上大學羅彩霞冒名頂替綜合癥 (Imposter Syndrome) Imposter Syndrome is a feeling of being a fraud or not being good enough to get the job done. Its common among software engineers, developers and designers working in tech companies, especially those n…