欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Flutter添加頁(yè)面過(guò)渡動(dòng)畫實(shí)現(xiàn)步驟

 更新時(shí)間:2022年05月16日 17:27:27   作者:會(huì)煮咖啡的貓咪  
這篇文章主要為大家介紹了Flutter添加頁(yè)面過(guò)渡動(dòng)畫,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

正文

大家好,在這篇文章中,我們將學(xué)習(xí)如何添加動(dòng)畫,同時(shí)從一個(gè)頁(yè)面到其他在 Flutter。我們將覆蓋不同類型的動(dòng)畫和實(shí)現(xiàn)基本動(dòng)畫 Flutter 使用包頁(yè)動(dòng)畫過(guò)渡。

動(dòng)畫在提升用戶體驗(yàn)方面起著至關(guān)重要的作用,但動(dòng)畫到底是什么呢?

設(shè)計(jì)語(yǔ)言,例如 Material,定義了在路線(或屏幕)之間轉(zhuǎn)換時(shí)的標(biāo)準(zhǔn)行為。不過(guò),有時(shí)候,自定義屏幕之間的轉(zhuǎn)換可以使應(yīng)用程序更加獨(dú)特。

在本教程中,我們將使用包頁(yè)面 page_animation_transition 來(lái)簡(jiǎn)化在頁(yè)面上添加轉(zhuǎn)換。

使用插件探索不同的轉(zhuǎn)換

步驟 1: 在 pubspec.yaml 中添加頁(yè)面動(dòng)畫轉(zhuǎn)換

page_animation_transition

步驟 2: 在 PageOne 上導(dǎo)入庫(kù)

假設(shè)您正在從 PageOne 過(guò)渡到 PageTwo

以下是圖書館支持的動(dòng)畫類型:

BottomToTopTransition   TopToBottomTransition  底到上轉(zhuǎn)換到底轉(zhuǎn)換

RightToLeftTransition 右轉(zhuǎn)移

LeftToRightTransition 左/右轉(zhuǎn)變

FadeAnimationTransition 淡化動(dòng)畫/轉(zhuǎn)換

ScaleAnimationTransition 標(biāo)量動(dòng)畫/轉(zhuǎn)換

RotationAnimationTransition 轉(zhuǎn)動(dòng)/動(dòng)畫/轉(zhuǎn)變

TopToBottomFadedTransition 上到下到過(guò)渡

BottomToTopFadedTransition 底部/上部/下部/上部/下部/上部/下部/上部/下部/上部/下部/上部/

RightToLeftFadedTransition 右轉(zhuǎn)到/ftfaded/transition

LeftToRightFadedTransition 左/右/插入/轉(zhuǎn)換

步驟3.添加以下導(dǎo)航代碼行

Navigator.of(context).push(PageAnimationTransition(page: const PageTwo(), pageAnimationType: BottomToTopTransition()));

對(duì)于預(yù)定義的路由:

onGenerateRoute: (settings) {
    switch (settings.name) {
      case '/pageTwo':
        return PageAnimationTransition(child: PageTwo(), pageAnimationType: LeftToRightFadedTransition());
        break;
      default:
        return null;
    }
  }

Navigator.pushNamed(context, '/pageTwo');

Pushnamed (context,’/pageTwo’) ;

Output:

輸出:

其他類型轉(zhuǎn)換的完整代碼:

import 'package:page_animation_transition/animations/bottom_to_top_faded_transition.dart';
import 'package:page_animation_transition/animations/bottom_to_top_transition.dart';
import 'package:page_animation_transition/animations/fade_animation_transition.dart';
import 'package:page_animation_transition/animations/left_to_right_faded_transition.dart';
import 'package:page_animation_transition/animations/left_to_right_transition.dart';
import 'package:page_animation_transition/animations/right_to_left_faded_transition.dart';
import 'package:page_animation_transition/animations/right_to_left_transition.dart';
import 'package:page_animation_transition/animations/rotate_animation_transition.dart';
import 'package:page_animation_transition/animations/scale_animation_transition.dart';
import 'package:page_animation_transition/animations/top_to_bottom_faded.dart';
import 'package:page_animation_transition/animations/top_to_bottom_transition.dart';
import 'package:page_animation_transition/page_animation_transition.dart';
import 'page_two.dart';
import 'package:flutter/material.dart';class PageOne extends StatelessWidget {
  const PageOne({Key? key}) : super(key: key);[@override](http://twitter.com/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page Animation Transition'),
        centerTitle: true,
      ),
      body: SizedBox(
        width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: BottomToTopTransition()));
                },
                child: const Text('Bottom To Top')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: TopToBottomTransition()));
                },
                child: const Text('Top to bottom')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: RightToLeftTransition()));
                },
                child: const Text('Right To Left')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: LeftToRightTransition()));
                },
                child: const Text('Left to Right')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: FadeAnimationTransition()));
                },
                child: const Text('Faded')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: ScaleAnimationTransition()));
                },
                child: const Text('Scale')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: RotationAnimationTransition()));
                },
                child: const Text('Rotate')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: TopToBottomFadedTransition()));
                },
                child: const Text('Top to Bottom Faded')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: BottomToTopFadedTransition()));
                },
                child: const Text('Bottom to Top Faded')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: RightToLeftFadedTransition()));
                },
                child: const Text('Right to Left Faded')),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(PageAnimationTransition(
                      page: const PageTwo(),
                      pageAnimationType: LeftToRightFadedTransition()));
                },
                child: const Text('Left to Right Faded')),
          ],
        ),
      ),
    );
  }
}

輸出:

總結(jié)

希望這個(gè)博客能幫助你深入了解 Flutter 的轉(zhuǎn)變。謝謝閱讀,更多關(guān)于Flutter頁(yè)面過(guò)渡動(dòng)畫的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論