| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- import 'package:flutter/material.dart';
- import '../widget/HomeDrawer.dart';
- import 'Setting.dart';
- import 'CreateRoom.dart';
- import 'RoomList.dart';
- import 'rankList.dart';
- import 'roomInfo.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import '../model/CompetitionSeason.dart';
- import '../styles/totast.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import 'TipList.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../model/UserInfo.dart';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- List<CompetitionSeason> seasonList = [];
- int nowIndex = 0;
- PageController _pageController;
- bool showBadge = false;
- void getSeasonInfo() async {
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get("competitionSeason/all");
- Toast.hide();
- if (res.success) {
- List<CompetitionSeason> list = [];
- for (var item in res.data) {
- list.add(CompetitionSeason.fromJson(item));
- }
- setState(() {
- seasonList = list;
- });
- } else {}
- }
- void showBackDialog() {
- showDialog<Null>(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return new AlertDialog(
- content: Container(
- height: 50,
- child: Text(
- '暂时没有进行中的房间,敬请期待...',
- style: TextStyle(color: Colors.black),
- ),
- ),
- actions: <Widget>[
- new FlatButton(
- child: new Text('确定'),
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- ],
- );
- },
- ).then((val) {});
- }
- void getOneRoom() async {
- Toast.show(context, '加载中', -1, 'loading');
- Result res =
- await HttpManager.get("houseInfo/getOne", data: {'statusFlag': 0});
- Toast.hide();
- if (res.success) {
- if (res.data != null) {
- Navigator.push(
- context,
- new CupertinoPageRoute(
- builder: (context) =>
- new RoomInfo(roomId: res.data['id'].toString())));
- } else {
- showBackDialog();
- }
- }
- }
- void getShowBadge() async {
- Result res = await HttpManager.get("systemNotice/unread", data: {
- 'userId': StoreProvider.of<AppState>(context).state.userInfo.id
- });
- if (res.success&&res.data!=null) {
- if (res.data>0) {
- setState(() {
- showBadge = true;
- });
- } else {
- setState(() {
- showBadge = false;
- });
- }
- }
- }
- @override
- void initState() {
- super.initState();
- _pageController = PageController(initialPage: 0);
- Future.delayed(Duration.zero, () {
- getSeasonInfo();
- getShowBadge();
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- drawer: HomeDrawer(),
- body: Container(
- width: double.infinity,
- height: double.infinity,
- decoration: BoxDecoration(
- gradient: LinearGradient(colors: [
- Color.fromARGB(255, 177, 59, 56),
- Color.fromARGB(255, 147, 64, 61)
- ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
- child: SafeArea(
- child: centerWidget(context),
- ),
- ),
- );
- }
- Widget centerWidget(BuildContext context) {
- return Column(
- children: <Widget>[
- Expanded(
- child: Stack(
- children: <Widget>[
- Container(
- child: seasonList.length > 0
- ? Swiper(
- index: nowIndex,
- itemCount: seasonList.length,
- scrollDirection: Axis.horizontal,
- loop: true,
- onTap: (index) {
- Navigator.push(
- context,
- new CupertinoPageRoute(
- builder: (context) => new RankList(
- raceId: seasonList[index].id)));
- },
- onIndexChanged: (index) {
- setState(() {
- nowIndex = index;
- });
- },
- itemBuilder: (context, index) {
- return Center(
- child: SizedBox(
- width: 214,
- height: 214,
- child: Stack(
- children: <Widget>[
- Image.asset("images/home_icon_yuan.png"),
- Center(
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.center,
- crossAxisAlignment:
- CrossAxisAlignment.baseline,
- textBaseline: TextBaseline.alphabetic,
- children: <Widget>[
- Text(
- (seasonList[index].bonus / 1000)
- .toStringAsFixed(1),
- style: TextStyle(
- color: Colors.white,
- fontSize: 68,
- fontFamily: 'AgencyFB',
- ),
- ),
- Text(
- "K",
- style: TextStyle(
- color: Colors.white,
- fontSize: 36,
- fontFamily: 'AgencyFB',
- ),
- )
- ],
- ),
- ),
- Positioned(
- bottom: 30,
- left: 0,
- right: 0,
- child: Column(
- children: <Widget>[
- // Text(
- // "当前排名",
- // style: TextStyle(
- // color: Colors.white, fontSize: 13),
- // ),
- // Text(
- // "98686",
- // style: TextStyle(
- // color: Colors.white, fontSize: 13),
- // )
- ],
- ),
- )
- ],
- )),
- );
- },
- )
- : Container()),
- Positioned(
- left: 0,
- top: 0,
- width: 48,
- height: 48,
- child: Material(
- color: Colors.transparent,
- child: Builder(
- builder: (context) => InkWell(
- onTap: () {
- Scaffold.of(context).openDrawer();
- },
- child: Padding(
- padding: EdgeInsets.all(12),
- child: Image.asset("images/home_icon_wode.png"),
- ),
- ),
- ),
- ),
- ),
- Positioned(
- right: 0,
- top: 0,
- width: 48,
- height: 48,
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: () {
- Navigator.push(
- context,
- new CupertinoPageRoute(
- builder: (context) => new Setting()));
- },
- child: Padding(
- padding: EdgeInsets.all(12),
- child: Image.asset("images/home_icon_shezhi.png"),
- ),
- ),
- ),
- ),
- Positioned(
- bottom: 11,
- left: 0,
- right: 0,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Text(
- seasonList.length > 0 ? seasonList[nowIndex].season : '',
- style: TextStyle(color: Colors.white, fontSize: 14),
- ),
- Text(
- seasonList.length > 0
- ? seasonList[nowIndex].gameInfo.gameName
- : '',
- style: TextStyle(color: Colors.white, fontSize: 14),
- )
- ],
- ),
- ),
- ],
- ),
- ),
- Container(
- child: GridView.count(
- physics: new BouncingScrollPhysics(),
- shrinkWrap: true,
- crossAxisCount: 2,
- children: <Widget>[
- HomeMenu(
- "images/home_icon_fangjian.png",
- "创建房间",
- onTapHomeMenu: () {
- Navigator.of(context).push(PageRouteBuilder(
- opaque: false,
- transitionDuration: Duration(milliseconds: 300),
- transitionsBuilder: (BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child) {
- return FadeTransition(
- opacity: CurvedAnimation(
- parent: animation, curve: Curves.linear),
- child: child,
- );
- },
- pageBuilder: (BuildContext context, _, __) {
- return CreateRoom();
- }));
- },
- ),
- HomeMenu(
- "images/home_icon_kuaisu.png",
- "快速进入",
- onTapHomeMenu: () {
- getOneRoom();
- },
- ),
- HomeMenu(
- "images/home_icon_sousuo.png",
- "搜索",
- onTapHomeMenu: () {
- Navigator.push(
- context,
- new CupertinoPageRoute(
- builder: (context) => new RoomList()));
- },
- ),
- HomeMenu(
- "images/home_icon_youjian.png",
- "邮件",
- onTapHomeMenu: () {
- Navigator.push(
- context,
- new CupertinoPageRoute(
- builder: (context) => new TipList()));
- },
- showBadge: showBadge,
- ),
- ],
- ),
- )
- ],
- );
- }
- }
- typedef int OnTapHomeMenu();
- class HomeMenu extends StatelessWidget {
- final String icon;
- final String title;
- final OnTapHomeMenu onTapHomeMenu;
- final bool showBadge;
- HomeMenu(this.icon, this.title, {this.onTapHomeMenu, this.showBadge = false});
- @override
- Widget build(BuildContext context) {
- return Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
- child: AspectRatio(
- aspectRatio: 1,
- child: Container(
- decoration: BoxDecoration(
- border: Border(
- left: BorderSide(width: 0.5, color: Color(0x80000000)),
- right: BorderSide(width: 0.5, color: Color(0x80000000)),
- bottom: BorderSide(width: 1, color: Color(0x80000000)))),
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: onTapHomeMenu,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- width: 44,
- height: 34,
- child: Stack(
- children: <Widget>[
- Image.asset(
- icon,
- fit: BoxFit.contain,
- width: 44,
- height: 34,
- ),
- Positioned(
- right: 0,
- top: 0,
- child: Container(
- width: showBadge ? 10 : 0,
- height: showBadge ? 10 : 0,
- decoration: BoxDecoration(
- color: Color.fromARGB(255, 239, 0, 9),
- borderRadius:
- BorderRadius.all(Radius.circular(10))),
- ),
- )
- ],
- ),
- ),
- Text(
- title,
- style: TextStyle(color: Colors.white, fontSize: 14),
- textAlign: TextAlign.center,
- )
- ],
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|