在Flutter中實現卡片切換效果可以通過使用PageView組件來實現。以下是一個簡單的示例代碼:
import 'package:flutter/material.dart';void main() { runApp(MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: CardSwitcher(), ); }}class CardSwitcher extends StatefulWidget { @override _CardSwitcherState createState() => _CardSwitcherState();}class _CardSwitcherState extends State<CardSwitcher> { PageController _pageController; int _currentIndex = 0; @override void initState() { _pageController = PageController(initialPage: _currentIndex); super.initState(); } @override void dispose() { _pageController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Card Switcher'), ), body: PageView( controller: _pageController, onPageChanged: (int index) { setState(() { _currentIndex = index; }); }, children: [ Card( color: Colors.red, child: Center( child: Text('Card 1', style: TextStyle(fontSize: 24, color: Colors.white)), ), ), Card( color: Colors.blue, child: Center( child: Text('Card 2', style: TextStyle(fontSize: 24, color: Colors.white)), ), ), Card( color: Colors.green, child: Center( child: Text('Card 3', style: TextStyle(fontSize: 24, color: Colors.white)), ), ), ], ), bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, onTap: (int index) { setState(() { _currentIndex = index; _pageController.animateToPage( _currentIndex, duration: Duration(milliseconds: 500), curve: Curves.ease, ); }); }, items: [ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Card 1', ), BottomNavigationBarItem( icon: Icon(Icons.business), label: 'Card 2', ), BottomNavigationBarItem( icon: Icon(Icons.school), label: 'Card 3', ), ], ), ); }}
在上面的示例代碼中,我們使用PageView組件來展示卡片,并通過PageController來控制卡片的切換。通過設置onPageChanged回調函數,我們可以在切換卡片時更新底部導航欄的當前選中項。通過點擊底部導航欄的選項,我們可以觸發動畫切換到對應的卡片。
本文由 貴州做網站公司 整理發布,部分圖文來源于互聯網,如有侵權,請聯系我們刪除,謝謝!
c語言中正確的字符常量是用一對單引號將一個字符括起表示合法的字符常量。例如‘a’。數值包括整型、浮點型。整型可用十進制,八進制,十六進制。八進制前面要加0,后面...
2022年天津專場考試原定于3月19日舉行,受疫情影響確定延期,但目前延期后的考試時間推遲。 符合報名條件的考生,須在規定時間登錄招考資訊網(www.zha...
:喜歡聽,樂意看。指很受歡迎?!巴卣官Y料”喜聞樂見:[ xǐ wén lè jiàn ]詳細解釋1. 【解釋】:喜歡聽,樂意看。指很受歡迎。2. 【示例】:這是...
房地產股票有哪些?房地產股票有綠地控股、順發恒業、蘇寧環球、世聯行、泰禾集團、中交地產、中國武夷、國興地產、津濱發展、嘉凱城、福星股份、天?;?、銀億股份等。房地產股票指的是房地產開發商或者公司發給股東當作入股憑證并以此獲得股息的一類有價證券。它代表著股東對企業或公司的財產權利。其發行方式一般是由房地產開發機構通過銀行進行金融性的發行。例中國第一家發行房地產股票的上海興業房產股份有限公司,便是委托...
房產稅是不是每年都要交?是的,每年都要交一次。房產稅指的是對房屋的產權所有人進行收稅。目前還沒有在全國范圍內普遍實行。-般來講,否應該交房產稅以及房產稅納稅期限由當地政府決定,具體有以下幾點。1、一套房普遍免征房產稅。但如果房屋占用公共資源和自然生態環境,或者有礙公序良俗時,就需要交房產稅,例如風景名勝區住房。另外,高檔住宅也需要交房產稅。2、二套房按免稅面積適度征收。商住房明確為非住宅,屬于財賠...
(相關資料圖)導讀 1、我正在看,正好是重播,遼寧衛視,激情唱響,鐘蒙修,太吃驚了,感覺歌聲不是從他嘴里出來的。2、感覺像是對口型,太震撼了··他叫鐘蒙修 22歲來自德州臨邑八里廟村我們大家都給他yes~!!!讓人很感動的小伙子鐘蒙修,遼寧衛視的激情唱響我也正在看,重播,遼寧衛視,激情唱響,鐘蒙修,山東人,太吃驚了,太帥了,他一開唱全場觀眾都站起來了。3、昨天看了重播 是廣西衛視的 激情唱響 節目...