基于flutter3.x跨端仿抖音app实战|flutter-douyin短视频直播
liuian 2025-05-21 14:58 38 浏览
又经过了半个多月的爆肝输出,全新原创的flutter3_douyin短视频直播项目完结了。
目前已经实现好的功能有首页、短视频、直播、聊天、我的等几个页面模块。
实现了类似抖音全屏沉浸式滑动效果(上下滑动视频、左右切换页面模块)。
实现了左右滑动的同时,顶部状态栏+Tab菜单+底部bottomNavigationBar导航栏三者联动效果。
技术栈
- 编辑器:Vscode
- 技术框架:Flutter3.19.2+Dart3.3.0
- 路由/状态管理:get: ^4.6.6
- 本地缓存:get_storage: ^2.1.1
- 图片预览插件:photo_view: ^0.14.0
- 刷新加载:easy_refresh^3.3.4
- toast轻提示:toast^0.3.0
- 视频套件:media_kit: ^1.1.10+1
为了考虑在windows端调试方便,目前视频播放器使用media_kit套件。
在开发的过程中,遇到了不少问题,最后都顺利解决了。
项目结构目录
预览图
flutter3底部导航菜单
使用 bottomNavigationBar 组件实现页面模块切换。通过getx全局状态来联动控制底部导航栏背景颜色。导航栏中间图标/图片按钮,使用了 Positioned 组件定位实现功能。
return Scaffold(
backgroundColor: Colors.grey[50],
body: pageList[pageCurrent],
// 底部导航栏
bottomNavigationBar: Theme(
// Flutter去掉BottomNavigationBar底部导航栏的水波纹
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
),
child: Obx(() {
return Stack(
children: [
Container(
decoration: const BoxDecoration(
border: Border(top: BorderSide(color: Colors.black54, width: .1)),
),
child: BottomNavigationBar(
backgroundColor: bottomNavigationBgcolor(),
fixedColor: FStyle.primaryColor,
unselectedItemColor: bottomNavigationItemcolor(),
type: BottomNavigationBarType.fixed,
elevation: 1.0,
unselectedFontSize: 12.0,
selectedFontSize: 12.0,
currentIndex: pageCurrent,
items: [
...pageItems
],
onTap: (index) {
setState(() {
pageCurrent = index;
});
},
),
),
// 自定义底部导航栏中间按钮
Positioned(
left: MediaQuery.of(context).size.width / 2 - 15,
top: 0,
bottom: 0,
child: InkWell(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Icon(Icons.tiktok, color: bottomNavigationItemcolor(centerDocked: true), size: 32.0,),
Image.asset('assets/images/applogo.png', width: 32.0, fit: BoxFit.contain,)
// Text('直播', style: TextStyle(color: bottomNavigationItemcolor(centerDocked: true), fontSize: 12.0),)
],
),
onTap: () {
setState(() {
pageCurrent = 2;
});
},
),
),
],
);
}),
),
);import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../styles/index.dart';
import '../../controllers/page_video_controller.dart';
// 引入pages页面
import '../pages/index/index.dart';
import '../pages/video/index.dart';
import '../pages/live/index.dart';
import '../pages/message/index.dart';
import '../pages/my/index.dart';
class Layout extends StatefulWidget {
const Layout({super.key});
@override
State<Layout> createState() => _LayoutState();
}
class _LayoutState extends State<Layout> {
PageVideoController pageVideoController = Get.put(PageVideoController());
// page索引
int pageCurrent = 0;
// page页面
List pageList = [const Index(), const FVideo(), const FLiveList(), const Message(), const My()];
// tabs选项
List pageItems = [
const BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: '首页'
),
const BottomNavigationBarItem(
icon: Icon(Icons.play_arrow_outlined),
label: '短视频'
),
const BottomNavigationBarItem(
icon: Icon(Icons.live_tv_rounded, color: Colors.transparent,),
label: ''
),
BottomNavigationBarItem(
icon: Stack(
alignment: const Alignment(4, -2),
children: [
const Icon(Icons.messenger_outline),
FStyle.badge(1)
],
),
label: '消息'
),
BottomNavigationBarItem(
icon: Stack(
alignment: const Alignment(1.5, -1),
children: [
const Icon(Icons.person_outline),
FStyle.badge(0, isdot: true)
],
),
label: '我'
)
];
// 底部导航栏背景色
Color bottomNavigationBgcolor() {
int index = pageCurrent;
int pageVideoTabIndex = pageVideoController.pageVideoTabIndex.value;
Color color = Colors.white;
if(index == 1) {
if([1, 2, 3].contains(pageVideoTabIndex)) {
color = Colors.white;
}else {
color = Colors.black;
}
}
return color;
}
// 底部导航栏颜色
Color bottomNavigationItemcolor({centerDocked = false}) {
int index = pageCurrent;
int pageVideoTabIndex = pageVideoController.pageVideoTabIndex.value;
Color color = Colors.black54;
if(index == 1) {
if([1, 2, 3].contains(pageVideoTabIndex)) {
color = Colors.black54;
}else {
color = Colors.white60;
}
}else if(index == 2 && centerDocked) {
color = FStyle.primaryColor;
}
return color;
}
// ...
}flutter3短视频滑动效果
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
forceMaterialTransparency: true,
backgroundColor: [1, 2, 3].contains(pageVideoController.pageVideoTabIndex.value) ? null : Colors.transparent,
foregroundColor: [1, 2, 3].contains(pageVideoController.pageVideoTabIndex.value) ? Colors.black : Colors.white,
titleSpacing: 1.0,
leading: Obx(() => IconButton(icon: Icon(Icons.menu, color: tabColor(),), onPressed: () {},),),
title: Obx(() {
return TabBar(
controller: tabController,
tabs: pageTabs.map((v) => Tab(text: v)).toList(),
isScrollable: true,
tabAlignment: TabAlignment.center,
overlayColor: MaterialStateProperty.all(Colors.transparent),
unselectedLabelColor: unselectedTabColor(),
labelColor: tabColor(),
indicatorColor: tabColor(),
indicatorSize: TabBarIndicatorSize.label,
unselectedLabelStyle: const TextStyle(fontSize: 16.0, fontFamily: 'Microsoft YaHei'),
labelStyle: const TextStyle(fontSize: 16.0, fontFamily: 'Microsoft YaHei', fontWeight: FontWeight.w600),
dividerHeight: 0,
labelPadding: const EdgeInsets.symmetric(horizontal: 10.0),
indicatorPadding: const EdgeInsets.symmetric(horizontal: 5.0),
onTap: (index) {
pageVideoController.updatePageVideoTabIndex(index); // 更新索引
pageController.jumpToPage(index);
},
);
}),
actions: [
Obx(() => IconButton(icon: Icon(Icons.search, color: tabColor(),), onPressed: () {},),),
],
),
body: Column(
children: [
Expanded(
child: Stack(
children: [
/// 水平滚动模块
PageView(
// 自定义滚动行为(支持桌面端滑动、去掉滚动条槽)
scrollBehavior: PageScrollBehavior().copyWith(scrollbars: false),
scrollDirection: Axis.horizontal,
controller: pageController,
onPageChanged: (index) {
pageVideoController.updatePageVideoTabIndex(index); // 更新索引
setState(() {
tabController.animateTo(index);
});
},
children: [
...pageModules
],
),
],
),
),
],
),
);短视频底部有一条播放进度条。
return Container(
color: Colors.black,
child: Column(
children: [
Expanded(
child: Stack(
children: [
/// 垂直滚动模块
PageView.builder(
// 自定义滚动行为(支持桌面端滑动、去掉滚动条槽)
scrollBehavior: PageScrollBehavior().copyWith(scrollbars: false),
scrollDirection: Axis.vertical,
controller: pageController,
onPageChanged: (index) async {
...
},
itemCount: videoList.length,
itemBuilder: (context, index) {
return Stack(
children: [
// 视频区域
Positioned(
top: 0,
left: 0,
right: 0,
bottom: 0,
child: GestureDetector(
child: Stack(
children: [
// 短视频插件
Visibility(
visible: videoIndex == index,
child: Video(
controller: videoController,
fit: BoxFit.cover,
// 无控制条
controls: NoVideoControls,
),
),
// 播放/暂停按钮
StreamBuilder(
stream: player.stream.playing,
builder: (context, playing) {
return Visibility(
visible: playing.data == false,
child: Center(
child: IconButton(
padding: EdgeInsets.zero,
onPressed: () {
player.playOrPause();
},
icon: Icon(
playing.data == true ? Icons.pause : Icons.play_arrow_rounded,
color: Colors.white70,
size: 70,
),
),
),
);
},
),
],
),
onTap: () {
player.playOrPause();
},
),
),
// 右侧操作栏
Positioned(
bottom: 15.0,
right: 10.0,
child: Column(
...
),
),
// 底部信息区域
Positioned(
bottom: 15.0,
left: 10.0,
right: 80.0,
child: Column(
...
),
),
// 播放mini进度条
Positioned(
bottom: 0.0,
left: 10.0,
right: 10.0,
child: Visibility(
visible: videoIndex == index && position > Duration.zero,
child: Listener(
child: SliderTheme(
data: const SliderThemeData(
trackHeight: 2.0,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 4.0), // 调整滑块的大小
// trackShape: RectangularSliderTrackShape(), // 使用矩形轨道形状
overlayShape: RoundSliderOverlayShape(overlayRadius: 0), // 去掉Slider默认上下边距间隙
inactiveTrackColor: Colors.white24, // 设置非活动进度条的颜色
activeTrackColor: Colors.white, // 设置活动进度条的颜色
thumbColor: Colors.pinkAccent, // 设置滑块的颜色
overlayColor: Colors.transparent, // 设置滑块覆盖层的颜色
),
child: Slider(
value: sliderValue,
onChanged: (value) async {
// debugPrint('当前视频播放时间$value');
setState(() {
sliderValue = value;
});
// 跳转播放时间
await player.seek(duration * value.clamp(0.0, 1.0));
},
onChangeEnd: (value) async {
setState(() {
sliderDraging = false;
});
// 继续播放
if(!player.state.playing) {
await player.play();
}
},
),
),
onPointerMove: (e) {
setState(() {
sliderDraging = true;
});
},
),
),
),
// 视频播放时间
Positioned(
bottom: 90.0,
left: 10.0,
right: 10.0,
child: Visibility(
visible: sliderDraging,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(position.label(reference: duration), style: const TextStyle(color: Colors.white, fontSize: 16.0, fontWeight: FontWeight.w600),),
Container(
margin: const EdgeInsets.symmetric(horizontal: 7.0),
child: const Text('/', style: TextStyle(color: Colors.white54, fontSize: 10.0,),),
),
Text(duration.label(reference: duration), style: const TextStyle(color: Colors.white54, fontSize: 16.0, fontWeight: FontWeight.w600),),
],
),
),
),
],
);
},
),
],
),
),
],
),
);Ok,限于篇幅,flutter3仿抖音短视频项目就先分享到这里。
相关推荐
- 磊科无线路由器手机设置(用手机 怎么设置磊科路由器怎么设置密码)
-
刚要回答你磊科无线路由器怎么设置无线网络这个大问题,看后面估计你更想知道的不是磊科无线路由器怎么设置无线网络,而是怎么用手机设置网络吧,其实很简单的,我刚才还用手机设置我刚买的极贰的网络 手机只...
- 萝卜家园xp系统安装(萝卜家园xp系统安装步骤及图片)
-
先用大白菜制作u盘启动项。再下载萝卜家园系统,放到u盘。开机选择用u盘启动,进入pe,打开ghost加载系统执行安装。
- 台式电脑显卡安装步骤图(台式机显卡怎么安装图解)
-
关于这个问题,1.确认电脑是否支持显卡首先,要确认电脑是否支持显卡。如果是台式机,需要确认主板是否支持PCI-E插槽;如果是笔记本电脑,则需要确认是否有可更换显卡的插槽。2.卸下原有显卡如果你的电...
- 虚拟光驱推荐(虚拟光驱推荐知乎)
-
虚拟光驱是一种计算机软件,用于模拟物理光驱的功能。它可以将光盘的内容转化为电脑上的虚拟光盘,用户可以在计算机上直接使用虚拟光盘中的文件和程序,而无需实际插入光盘。虚拟光驱的主要功能包括:1.安装软件...
- win7和win10互联(win7和win10可以网络共享吗)
-
一台电脑只要已经使用过一次已经激活的win10,以后可以随便重装win10,都会自动激活。不限制次数,只要你不把这台电脑的主板给换掉即可。所以可以随时重装,或者也可以使用win7、win8.1的密钥...
- 电脑给另一个硬盘装系统(电脑给另一块硬盘装系统)
-
回答如下:以下是在Windows操作系统下的步骤:1.确保你有一个可用的Windows安装光盘或USB安装介质。2.将另一个硬盘连接到计算机上并确保电脑识别到它。3.打开计算机BIOS并确保在启...
- 设计师专用笔记本电脑排行榜
-
惠普战99采用了英特尔第十二代酷睿i7-12700H标压处理器和英伟达T600工作站级专业显卡的配置。存储方面支持双通道3200MHz内存和双M.2接口SSD,配置十分豪华。15.6英寸高色域高清IP...
-
- 打印机故障排查(打印机故障排查提示不接收任务怎么处理)
-
步骤/方式1点击电脑桌面左下角的开始按钮,选择设备和打印机的选项。步骤/方式2找到有故障的打印机,鼠标右键点击选择属性的选项。步骤/方式3在打印机属性页面,我们点击维护的选项。步骤/方式4在维护页面,选择对应的故障进行维护,即可解决故障亮灯...
-
2026-01-09 19:55 liuian
- 内部版本7601激活(内部版本7601影响使用吗)
-
激活方法如下右击计算机--属性,拉倒最下面,会提示该系统未激活,然后点击激活,输入密钥就可以了,需要连接互联网。如果没有互联网,也可以电话激活。下载安装内部专用激活工具激活就可以了Windows7内部...
- microsoft打不开怎么办(microsoftoffice打不开)
-
方法一:1、按Win+S组合键,或点击底部任务栏开始旁的搜索图标,在打开的Windows搜索窗口,搜索框输入服务,然后点击打开系统给出的最佳匹配服务应用;2、服务窗口,找到并双击打开WLA...
- 安卓仿苹果ios主题下载免费(安卓仿苹果ios12主题下载)
-
要把华为手机的主题改成类似iOS的风格,可以按照以下步骤进行操作:1.在华为应用商店中搜索并下载一个适合的iOS主题,例如iOSLauncher等。2.安装完成后,打开该主题应用,在设置中选择启...
- 声卡驱动安装哪个比较好(声卡驱动应该安装在哪里)
-
EXPSoundboard软件使用电脑自带的集成声卡就可以了。只是需要安装一些变声软件。如EXPSoundboard软件,使用这款EXPSoundboard中文版可以让你自由自在的在任何游戏中挂...
- 宽带登录网站(宽带登录网站怎么登录)
-
在浏览器内输入www.10010.com,进入中国联通网上营业厅后,选择“登录”,输入宽带账号与宽带密码,点击登录即可使用联通宽带登录联通网上营业厅。可通过以下方式办理联通宽带预约服务:1、登录联通网...
- tenda官网登入(tenda官网192.168.0.1登录)
-
腾达无线的路由器登录入口是:tplogin.cn电信运营商定制款登录地址是:192.168.2.1或者192.168.8.12、华为(容易)路由器华为路由器跟荣耀路由器只有IP地址,没有域名,它是...
- 一周热门
-
-
飞牛OS入门安装遇到问题,如何解决?
-
如何在 iPhone 和 Android 上恢复已删除的抖音消息
-
Boost高性能并发无锁队列指南:boost::lockfree::queue
-
大模型手册: 保姆级用CherryStudio知识库
-
用什么工具在Win中查看8G大的log文件?
-
如何在 Windows 10 或 11 上通过命令行安装 Node.js 和 NPM
-
威联通NAS安装阿里云盘WebDAV服务并添加到Infuse
-
Trae IDE 如何与 GitHub 无缝对接?
-
idea插件之maven search(工欲善其事,必先利其器)
-
如何修改图片拍摄日期?快速修改图片拍摄日期的6种方法
-
- 最近发表
- 标签列表
-
- python判断字典是否为空 (50)
- crontab每周一执行 (48)
- aes和des区别 (43)
- bash脚本和shell脚本的区别 (35)
- canvas库 (33)
- dataframe筛选满足条件的行 (35)
- gitlab日志 (33)
- lua xpcall (36)
- blob转json (33)
- python判断是否在列表中 (34)
- python html转pdf (36)
- 安装指定版本npm (37)
- idea搜索jar包内容 (33)
- css鼠标悬停出现隐藏的文字 (34)
- linux nacos启动命令 (33)
- gitlab 日志 (36)
- adb pull (37)
- python判断元素在不在列表里 (34)
- python 字典删除元素 (34)
- vscode切换git分支 (35)
- python bytes转16进制 (35)
- grep前后几行 (34)
- hashmap转list (35)
- c++ 字符串查找 (35)
- mysql刷新权限 (34)
