home_page.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import 'package:battle/route.dart';
  2. import 'package:flutter/material.dart';
  3. import '../data/card.dart';
  4. class HomePage extends StatefulWidget {
  5. const HomePage({super.key});
  6. @override
  7. State<HomePage> createState() => _HomePageState();
  8. }
  9. class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  10. late TabController _tabController;
  11. @override
  12. void initState() {
  13. super.initState();
  14. _tabController = TabController(length: 3, vsync: this);
  15. }
  16. @override
  17. void dispose() {
  18. _tabController.dispose();
  19. super.dispose();
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. appBar: AppBar(
  25. title: Text(
  26. '逻辑狗AI对抗',
  27. style: TextStyle(color: Theme.of(context).colorScheme.primary),
  28. ),
  29. centerTitle: true,
  30. backgroundColor: Theme.of(context).colorScheme.surface,
  31. ),
  32. body: Column(
  33. children: [
  34. SizedBox(
  35. width: double.infinity,
  36. height: 64,
  37. child: TabBar(
  38. controller: _tabController,
  39. tabs: const [
  40. Tab(text: '小班下'),
  41. Tab(text: '中班下'),
  42. Tab(text: '大班下'),
  43. ],
  44. ),
  45. ),
  46. const SizedBox(height: 16),
  47. Expanded(
  48. child: TabBarView(
  49. controller: _tabController,
  50. children: [
  51. GridView.count(
  52. crossAxisCount: 2,
  53. mainAxisSpacing: 8.0,
  54. crossAxisSpacing: 8.0,
  55. padding: const EdgeInsets.symmetric(horizontal: 16),
  56. childAspectRatio: 1 / 1.6,
  57. children: smallCardList.map(_buildCard).toList(),
  58. ),
  59. GridView.count(
  60. crossAxisCount: 2,
  61. mainAxisSpacing: 8.0,
  62. crossAxisSpacing: 8.0,
  63. padding: const EdgeInsets.symmetric(horizontal: 16),
  64. childAspectRatio: 1 / 1.6,
  65. children: middleCardList.map(_buildCard).toList(),
  66. ),
  67. GridView.count(
  68. crossAxisCount: 2,
  69. mainAxisSpacing: 8.0,
  70. crossAxisSpacing: 8.0,
  71. padding: const EdgeInsets.symmetric(horizontal: 16),
  72. childAspectRatio: 1 / 1.6,
  73. children: seniorCardList.map(_buildCard).toList(),
  74. ),
  75. ],
  76. ),
  77. ),
  78. ],
  79. ),
  80. );
  81. }
  82. Widget _buildCard(CardItem card) {
  83. return GestureDetector(
  84. onTap: () => GameRouter(
  85. cardName: card.cardName,
  86. assetPath: card.assetPath,
  87. answer: card.answer,
  88. ).push(context),
  89. child: Card(
  90. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
  91. clipBehavior: Clip.antiAlias,
  92. child: Column(
  93. crossAxisAlignment: CrossAxisAlignment.start,
  94. children: [
  95. Image.asset(card.assetPath),
  96. Expanded(
  97. child: Align(
  98. alignment: Alignment.centerLeft,
  99. child: Padding(
  100. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  101. child: Text(card.cardName),
  102. ),
  103. ),
  104. ),
  105. ],
  106. ),
  107. ),
  108. );
  109. }
  110. }