搜索分类、插件与代码仓

animated_appbar 封面
插件详情v2.1.5

animated_appbar

可随页面导航动态改变高度的 AppBar。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
105
喜欢数
29
Pub 分数
160

安装插件

flutter pub add animated_appbar

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可使 AppBar 在页面导航过程中动态调整其高度,提供流畅且视觉吸引人的用户体验。它会自动根据滚动或路由过渡动画调整 AppBar 的大小,非常适合具有复杂导航流程的应用程序。该包轻量级,并能与现有的 Flutter 项目无缝集成。支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

适合场景

  • 可滚动页面中的动态标题调整大小
  • 屏幕之间平滑过渡,应用栏高度变化
  • 使用视差效果创建沉浸式用户界面
  • 增强复杂应用结构中的导航体验
  • 在多页应用程序中实现响应式应用栏

主要特点

  • 在导航过程中自动调整应用栏高度
  • 高度过渡的平滑动画
  • 跨平台兼容性
  • 与 MaterialApp 和 Navigator 的轻松集成
  • 支持自定义高度曲线和缓动

适合对象

  • 开发交互式和动画用户界面的开发者
  • 需要动态标题的应用程序
  • 设计师专注于流畅的导航体验
  • 面向多个平台的项目
  • Flutter 初学者学习有状态动画

使用建议

  • 可能需要仔细处理嵌套导航器
  • 在旧设备上使用大量动画时的性能影响
  • 超出高度更改之外的自定义功能有限
  • 不适用于静态应用栏设计
  • 需要理解 ScrollController 和 PageView 的交互

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

animated_appbar

pub package License: MIT

AppBar which can dynamically change height with page navigation. preview

Usage

This package is expected to be used with BaseLayout and AnimatedAppBar

// In this scenario
// we have to pages.
// In Page1, We will navigate to Page2 with dynamic animations.
// In Page2, We will back to Page1 with dynamic animations.
import 'package:flutter/material.dart';
import 'package:animated_appbar/animated_appbar.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with TickerProviderStateMixin{
  
  @override
  Widget build(BuildContext context) {
    
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      // BaseLayout is declared in this package
      // If you wanna using AnimatedAppBar, You must use [BaseLayout]
      home: BaseLayout(
        // AnimatedAppBar is declared in this package
        appBar: AnimatedAppBar(
          initHeight: 135.0,
          backgroundColor: Color(0xff7a7ad1),
          child: Container(
            // If you want to change your appbar,
            // You must set key like this.
            // If you don't set this properties,
            // You couldn't see beautiful animation.
            key: UniqueKey(),
            child:Center(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Icon(
                    Icons.apps,
                    color: Colors.white,
                    size: 20.0,
                  ),
                  Text(
                    "You can customise this Area",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20.0,
                    ),  
                  ),
                  Icon(
                    Icons.manage_search,
                    color: Colors.white,
                    size: 20.0,
                  ),
                ],
              ),
            ),
          ),
        ),
        // Setting initial Page in here!!!!!
        scaffold: Page1(),
      ),
    );
  }
}

// When routing page with this package,
// You must write [with RoutePage] like below.
// In this class, routing methods are defined.
class Page1 extends StatelessWidget with RoutePage{
  // This variable is Page2's new AppBar widget.
  // You have not using AnimatedAppBar
  // Just use any other Widget without AnimatedAppBar
  Widget newAppBar = Container(
    // You must set key like this.
    // If you don't set this properties,
    // You couldn't see beautiful animation.
    key:UniqueKey(),
    child:Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(
          "AppBar changed!!",
          style: TextStyle(
            color: Color(0xfff7f4cc),
            fontSize: 20,
          ),
        ),
        Text(
          "You can customise here too..🔥",
          style: TextStyle(
            color: Color(0xfff7f4cc),
            fontSize: 20,
          ),
        ),
      ],
    ),
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:  Center(
        child:Column(
          mainAxisAlignment:MainAxisAlignment.center,
          children: [
            Text(
              "Page 1 😄",
              style:TextStyle(
                fontSize: 50,
              ),
            ),
            SizedBox(height: 5),
            Container(
              decoration:BoxDecoration(
                color: Colors.blue,
                borderRadius: BorderRadius.all(
                  Radius.circular(8)
                ),
              ),
              padding: EdgeInsets.all(10.0),
              child: TextButton(
                  // If you wanna route page, Using routePage(Widget page)!
                  // Ig you wannt route page with new appbar, Using routePageWithNewAppBar(widget page, widget appBar)
                  onPressed: ()=> routePageWithNewAppBar(Page2(),newAppBar),
                  child: Text(
                    "Click here to navigate Page2!",
                    style: TextStyle(
                      fontSize: 20,
                      color: Colors.white
                    ),
                  ),
                ),
            ),
          ],
        ),
      ),
    );
  }
}

class Page2 extends StatelessWidget with RoutePage{
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:  Center(
        child:Column(
          mainAxisAlignment:MainAxisAlignment.center,
          children: [
            Text(
              "Page 2 🚩",
              style:TextStyle(
                fontSize: 50,
              ),
            ),
            SizedBox(height: 5),
            Container(
              decoration:BoxDecoration(
                color: Colors.red,
                borderRadius: BorderRadius.all(
                  Radius.circular(8)
                ),
              ),
              padding: EdgeInsets.all(10.0),
              child: TextButton(
                // If you wanna back to previous page, Just using [previousPage()] method.  
                onPressed: () => previousPage(),
                child: Text(
                  "back to Page1",
                  style: TextStyle(
                    fontSize: 20,
                    color: Colors.white
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

If you have any requests / contributes or questions, please feel free to visit github.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。