241 lines
8.1 KiB
Dart
241 lines
8.1 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:talk/tools/home/my_home_page.dart';
|
|
import 'package:talk/tools/me/me_page.dart';
|
|
import 'package:talk/tools/message/message_page.dart';
|
|
|
|
import '../network/NetworkConfig.dart';
|
|
import 'find/find_page.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
|
|
int currentIndex = 0;
|
|
late final TabController _tabController;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
_tabController = TabController(length: 4, vsync: this);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
_tabController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return WillPopScope(
|
|
onWillPop: doubleClickBack,
|
|
child: Scaffold(
|
|
backgroundColor: Color(0x32FFFFFF),
|
|
body: Stack(
|
|
children: <Widget>[
|
|
TabBarView(
|
|
controller: _tabController,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
children: const [
|
|
MyHomePage(),
|
|
FindPage(),
|
|
MessagePage(),
|
|
MePage(),
|
|
],
|
|
),
|
|
// Positioned(
|
|
// bottom: 0,
|
|
// child: Container(
|
|
// width: MediaQuery.of(context).size.width,
|
|
// height: 60,
|
|
// color: Color(currentIndex != 0 ? 0xFF121213 : 0x121213),
|
|
// child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
// children: [
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// currentIndex = 0;
|
|
// _tabController.animateTo(0);
|
|
// setState(() {});
|
|
// },
|
|
// child: Text(
|
|
// '首页',
|
|
// style: TextStyle(color: Color(currentIndex == 0 ? 0xFFFFFFFF : 0xFF7E7E7E)),
|
|
// ),
|
|
// ),
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// if (NetworkConfig.userId == "") {
|
|
// Navigator.of(context).pushNamed('/LoginPage');
|
|
// return;
|
|
// }
|
|
//
|
|
// currentIndex = 1;
|
|
// _tabController.animateTo(1);
|
|
// setState(() {});
|
|
// },
|
|
// child: Text(
|
|
// '发现',
|
|
// style: TextStyle(color: Color(currentIndex == 1 ? 0xFFFFFFFF : 0xFF7E7E7E)),
|
|
// ),
|
|
// ),
|
|
// Image(
|
|
// width: 32,
|
|
// image: AssetImage('assets/images/ic_create.png'),
|
|
// ),
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// if (NetworkConfig.userId == "") {
|
|
// Navigator.of(context).pushNamed('/LoginPage');
|
|
// return;
|
|
// }
|
|
// currentIndex = 2;
|
|
// _tabController.animateTo(2);
|
|
// setState(() {});
|
|
// },
|
|
// child: Text(
|
|
// '消息',
|
|
// style: TextStyle(color: Color(currentIndex == 2 ? 0xFFFFFFFF : 0xFF7E7E7E)),
|
|
// ),
|
|
// ),
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// if (NetworkConfig.userId == "") {
|
|
// Navigator.of(context).pushNamed('/LoginPage');
|
|
// return;
|
|
// }
|
|
// currentIndex = 3;
|
|
// _tabController.animateTo(3);
|
|
// setState(() {});
|
|
// },
|
|
// child: Text(
|
|
// '我的',
|
|
// style: TextStyle(color: Color(currentIndex == 3 ? 0xFFFFFFFF : 0xFF7E7E7E)),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ))
|
|
],
|
|
),
|
|
bottomNavigationBar: Theme(
|
|
data: ThemeData(
|
|
splashFactory: NoSplash.splashFactory, // 全局移除水波纹效果
|
|
highlightColor: Colors.transparent, // 全局移除点击高亮效果
|
|
),
|
|
child: BottomNavigationBar(
|
|
backgroundColor: Color(0xFF0C0909),
|
|
type: BottomNavigationBarType.fixed,
|
|
items: <BottomNavigationBarItem>[
|
|
BottomNavigationBarItem(
|
|
icon: Container(
|
|
child: Text(
|
|
'首页',
|
|
style: TextStyle(color: Color(currentIndex == 0 ? 0xFFFFFFFF : 0xFF7E7E7E), fontSize: 15),
|
|
),
|
|
),
|
|
label: '',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Container(
|
|
child: Text(
|
|
'发现',
|
|
style: TextStyle(color: Color(currentIndex == 1 ? 0xFFFFFFFF : 0xFF7E7E7E), fontSize: 15),
|
|
),
|
|
),
|
|
label: '',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Container(
|
|
// margin: EdgeInsets.only(top: 10),
|
|
child: Image(
|
|
width: 32,
|
|
image: AssetImage('assets/images/ic_create.png'),
|
|
),
|
|
),
|
|
label: '',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Container(
|
|
child: Text(
|
|
'消息',
|
|
style: TextStyle(color: Color(currentIndex == 3 ? 0xFFFFFFFF : 0xFF7E7E7E), fontSize: 15),
|
|
),
|
|
),
|
|
label: '',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Container(
|
|
child: Text(
|
|
'我的',
|
|
style: TextStyle(color: Color(currentIndex == 4 ? 0xFFFFFFFF : 0xFF7E7E7E), fontSize: 15),
|
|
),
|
|
),
|
|
label: '',
|
|
),
|
|
],
|
|
// 初始选中的索引
|
|
currentIndex: currentIndex,
|
|
// 选中项的颜色
|
|
// selectedItemColor: Color(0xFFFFFFFF),
|
|
// // 未选中项的颜色
|
|
// unselectedItemColor: Color(0xFF7E7E7E),
|
|
selectedFontSize: 15,
|
|
unselectedFontSize: 15,
|
|
iconSize: 0,
|
|
onTap: (index) {
|
|
|
|
if (NetworkConfig.userId == "") {
|
|
Navigator.of(context).pushNamed('/LoginPage');
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
currentIndex = index;
|
|
});
|
|
|
|
switch (index) {
|
|
case 2:
|
|
break;
|
|
case 3:
|
|
_tabController.animateTo(2);
|
|
break;
|
|
case 4:
|
|
_tabController.animateTo(3);
|
|
break;
|
|
default:
|
|
_tabController.animateTo(index);
|
|
break;
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
int last = 0;
|
|
|
|
Future<bool> doubleClickBack() async {
|
|
int now = DateTime.now().millisecondsSinceEpoch;
|
|
|
|
if (now - last > 2500) {
|
|
last = DateTime.now().millisecondsSinceEpoch;
|
|
EasyLoading.showToast("再按一次退出");
|
|
return Future.value(false);
|
|
} else {
|
|
exit(0);
|
|
}
|
|
}
|
|
}
|