193 lines
5.2 KiB
Dart
193 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:game/network/NetworkConfig.dart';
|
|
import 'package:game/tools/shop/shop_page.dart';
|
|
import 'package:lottie/lottie.dart';
|
|
|
|
import '../common/Global.dart';
|
|
import 'game/game_page.dart';
|
|
import 'home/my_home_page.dart';
|
|
import 'me/my_page.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|
final pageController = PageController();
|
|
|
|
List<StatefulWidget> bodyList = [MyHomePage(), GamePage(), ShopPage(), MyPage()];
|
|
|
|
int currentIndex = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
super.dispose();
|
|
}
|
|
|
|
void onPageChanged(int index) {
|
|
// streamSink.add(index);
|
|
if (NetworkConfig.token == "") {
|
|
Navigator.pushNamed(context, "/LoginPage");
|
|
return;
|
|
}
|
|
setState(() {
|
|
currentIndex = index;
|
|
});
|
|
pageController.jumpToPage(index);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Color(0xFF17181A),
|
|
body: Stack(
|
|
children: [
|
|
PageView(
|
|
controller: pageController,
|
|
// onPageChanged: onPageChanged,
|
|
children: bodyList,
|
|
physics: NeverScrollableScrollPhysics(), // 禁止滑动
|
|
)
|
|
],
|
|
),
|
|
bottomNavigationBar: BottomAppBar(
|
|
elevation: 0,
|
|
height: 74,
|
|
color: Color(0xFF171B23),
|
|
child: bottomItem(),
|
|
),
|
|
);
|
|
}
|
|
|
|
///底部导航item
|
|
bottomItem() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
onPageChanged(0);
|
|
},
|
|
child: Stack(
|
|
children: [
|
|
currentIndex == 0
|
|
? SizedBox(
|
|
width: 47,
|
|
height: 47,
|
|
child: Lottie.asset(
|
|
'assets/animation/an_home.json',
|
|
repeat: false,
|
|
),
|
|
)
|
|
: Container(
|
|
margin: EdgeInsets.only(top: 5),
|
|
child: Image(
|
|
width: 47,
|
|
height: 47,
|
|
image: AssetImage('assets/images/ic_home.png'),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
onPageChanged(1);
|
|
},
|
|
child: Container(
|
|
child: Stack(
|
|
children: [
|
|
currentIndex == 1
|
|
? SizedBox(
|
|
width: 47,
|
|
height: 47,
|
|
child: Lottie.asset(
|
|
'assets/animation/an_game.json',
|
|
repeat: false,
|
|
),
|
|
)
|
|
: Container(
|
|
margin: EdgeInsets.only(top: 5),
|
|
child: Image(width: 47, height: 47, image: AssetImage('assets/images/ic_game.png')),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
onPageChanged(2);
|
|
},
|
|
child: Container(
|
|
child: Stack(
|
|
children: [
|
|
currentIndex == 2
|
|
? SizedBox(
|
|
width: 47,
|
|
height: 47,
|
|
child: Lottie.asset(
|
|
'assets/animation/an_shop.json',
|
|
repeat: false,
|
|
),
|
|
)
|
|
: Container(
|
|
margin: EdgeInsets.only(top: 5),
|
|
child: Image(width: 47, height: 47, image: AssetImage('assets/images/ic_shop.png')),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
onPageChanged(3);
|
|
},
|
|
child: Container(
|
|
child: Stack(
|
|
children: [
|
|
currentIndex == 3
|
|
? SizedBox(
|
|
width: 47,
|
|
height: 47,
|
|
child: Lottie.asset(
|
|
'assets/animation/an_me.json',
|
|
repeat: false,
|
|
),
|
|
)
|
|
: Container(
|
|
margin: EdgeInsets.only(top: 5),
|
|
child: Image(
|
|
width: 47,
|
|
height: 47,
|
|
image: AssetImage('assets/images/ic_me.png'),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
// 获取原生的值
|
|
invokeNativeMethod(String method, Map<String, dynamic> map) async {
|
|
dynamic args;
|
|
try {
|
|
args = await Global.method.invokeMethod(method, map);
|
|
} on PlatformException catch (e) {}
|
|
}
|