135 lines
4.2 KiB
Dart
135 lines
4.2 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 '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: [
|
|
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: () {
|
|
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: () {
|
|
currentIndex = 2;
|
|
_tabController.animateTo(2);
|
|
setState(() {});
|
|
},
|
|
child: Text(
|
|
'消息',
|
|
style: TextStyle(color: Color(currentIndex == 2 ? 0xFFFFFFFF : 0xFF7E7E7E)),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
currentIndex = 3;
|
|
_tabController.animateTo(3);
|
|
setState(() {});
|
|
},
|
|
child: Text(
|
|
'我的',
|
|
style: TextStyle(color: Color(currentIndex == 3 ? 0xFFFFFFFF : 0xFF7E7E7E)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|