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/: 示例应用的主要代码文件夹。
-
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,
),
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考