index.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:sport/pages/game/game_info.dart';
  4. import 'package:sport/pages/game/rank_info.dart';
  5. class GamePage extends StatefulWidget{
  6. @override
  7. State<StatefulWidget> createState() {
  8. return _GamePageState();
  9. }
  10. }
  11. class _GamePageState extends State<GamePage> with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin{
  12. TabController _tabController;
  13. List<Widget> _pages = [];
  14. @override
  15. void initState(){
  16. super.initState();
  17. _tabController = new TabController(length: 2, vsync: this);
  18. _pages = <Widget>[ // 运动的View
  19. GameInfoView(),
  20. // 榜单的View
  21. RankInfo(),];
  22. }
  23. @override
  24. void dispose() {
  25. super.dispose();
  26. _tabController?.dispose();
  27. }
  28. @override
  29. bool get wantKeepAlive => true;
  30. @override
  31. void didChangeDependencies() {
  32. super.didChangeDependencies();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. super.build(context);
  37. return Scaffold(
  38. appBar: AppBar(
  39. elevation: 0, // 去掉AppBar下面的阴影
  40. title: SizedBox(
  41. height: 30,
  42. child: TabBar(
  43. isScrollable: true,
  44. indicatorPadding: EdgeInsets.symmetric(horizontal: 10.0),
  45. indicatorWeight: 3,
  46. labelStyle:TextStyle(fontSize: 18.0,fontWeight: FontWeight.w600),
  47. unselectedLabelStyle: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w600),
  48. labelPadding:EdgeInsets.symmetric(vertical: 0.0,horizontal: 30.0),
  49. // indicator: const BoxDecoration(),
  50. // labelPadding: EdgeInsets.all(20.0),
  51. tabs: <Widget>[
  52. Tab(
  53. text: "运动",
  54. ),
  55. Tab(
  56. text:"榜单"
  57. )
  58. ],
  59. controller: _tabController,
  60. ),
  61. ),
  62. ),
  63. body: Container(
  64. color: Colors.white,
  65. child: TabBarView(
  66. controller: _tabController,
  67. children: _pages,
  68. ),
  69. )
  70. );
  71. }
  72. }