index.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. backgroundColor: Colors.white,
  39. appBar: AppBar(
  40. elevation: 0, // 去掉AppBar下面的阴影
  41. title: SizedBox(
  42. height: 30,
  43. child: TabBar(
  44. isScrollable: true,
  45. indicatorPadding: EdgeInsets.symmetric(horizontal: 10.0),
  46. indicatorWeight: 3,
  47. labelStyle:TextStyle(fontSize: 18.0,fontWeight: FontWeight.w600),
  48. unselectedLabelStyle: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w600),
  49. labelPadding:EdgeInsets.symmetric(vertical: 0.0,horizontal: 30.0),
  50. // indicator: const BoxDecoration(),
  51. // labelPadding: EdgeInsets.all(20.0),
  52. tabs: <Widget>[
  53. Tab(
  54. text: "运动",
  55. ),
  56. Tab(
  57. text:"榜单"
  58. )
  59. ],
  60. controller: _tabController,
  61. ),
  62. ),
  63. ),
  64. body: Container(
  65. color: Colors.white,
  66. child: TabBarView(
  67. controller: _tabController,
  68. children: _pages,
  69. ),
  70. )
  71. );
  72. }
  73. }