Motion-Tab-Bar 项目教程

Motion-Tab-Bar 项目教程

Motion-Tab-BarA beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.项目地址:https://gitcode.com/gh_mirrors/mo/Motion-Tab-Bar

1. 项目的目录结构及介绍

Motion-Tab-Bar 项目的目录结构如下:

Motion-Tab-Bar/
├── example/
│   ├── lib/
│   │   ├── main.dart
│   ├── pubspec.yaml
├── lib/
│   ├── motion-tab-bar.dart
│   ├── motion-badge-widget.dart
│   ├── motion-tab-controller.dart
├── pubspec.yaml

目录结构介绍

  • example/: 包含项目的示例应用。

    • lib/: 示例应用的主要代码文件夹。
      • main.dart: 示例应用的入口文件。
    • pubspec.yaml: 示例应用的依赖配置文件。
  • lib/: 包含 Motion-Tab-Bar 的核心库文件。

    • motion-tab-bar.dart: 定义了 MotionTabBar 组件。
    • motion-badge-widget.dart: 定义了 MotionBadgeWidget 组件。
    • motion-tab-controller.dart: 定义了 MotionTabController 控制器。
  • pubspec.yaml: 项目的依赖配置文件。

2. 项目的启动文件介绍

项目的启动文件位于 example/lib/main.dart。以下是该文件的主要内容:

import 'package:flutter/material.dart';
import 'package:motion_tab_bar_v2/motion-tab-bar.dart';
import 'package:motion_tab_bar_v2/motion-badge-widget.dart';
import 'package:motion_tab_bar_v2/motion-tab-controller.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Motion Tab Bar Sample',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Motion Tab Bar Sample'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  late MotionTabBarController _motionTabBarController;

  @override
  void initState() {
    super.initState();
    _motionTabBarController = MotionTabBarController(
      initialIndex: 1,
      length: 4,
      vsync: this,
    );
  }

  @override
  void dispose() {
    _motionTabBarController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: _motionTabBarController,
        children: const [
          Center(child: Text('Dashboard')),
          Center(child: Text('Home')),
          Center(child: Text('Profile')),
          Center(child: Text('Settings')),
        ],
      ),
      bottomNavigationBar: MotionTabBar(
        controller: _motionTabBarController,
        initialSelectedTab: "Home",
        labels: const ["Dashboard", "Home", "Profile", "Settings"],
        icons: const [
          Icons.dashboard,
          Icons.home,
          Icons.people_alt,
          Icons.settings
        ],
        badges: [
          const MotionBadgeWidget(
            text: '10+',
            textColor: Colors.white,
            color: Colors.red,
            size: 18,
          ),
          Container(
            color: Colors.black,
            padding: const EdgeInsets.all(2),
            child: const Text(
              '11',
              style: TextStyle(
                fontSize: 14,
                color: Colors.white,
              ),

Motion-Tab-BarA beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.项目地址:https://gitcode.com/gh_mirrors/mo/Motion-Tab-Bar

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

霍曙柏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值