game_page.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import 'package:battle/button/button_controller.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:widget/widget.dart';
  4. import '../button/button_painter.dart';
  5. class GamePage extends StatefulWidget {
  6. const GamePage({super.key});
  7. @override
  8. State<GamePage> createState() => _GamePageState();
  9. }
  10. class _GamePageState extends State<GamePage> with SingleTickerProviderStateMixin {
  11. late ButtonController _controller;
  12. @override
  13. void initState() {
  14. super.initState();
  15. _controller = ButtonController(vsync: this);
  16. _controller.start();
  17. }
  18. void _reset() {
  19. _controller.reset();
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. body: Stack(
  25. children: [
  26. Positioned.fill(
  27. child: ColorFiltered(
  28. colorFilter: const ColorFilter.matrix(<double>[
  29. 1, 0, 0, 0, 0, //r
  30. 0, 1, 0, 0, 0, //r
  31. 0, 0, 1, 0, 0, //r
  32. 0, 0, 0, 0.25, 0, //r
  33. ]),
  34. child: Image.asset(
  35. 'assets/images/background.png',
  36. repeat: ImageRepeat.repeat,
  37. cacheWidth: 30,
  38. cacheHeight: 30,
  39. ),
  40. ),
  41. ),
  42. Positioned.fill(
  43. child: Column(
  44. children: [
  45. Expanded(
  46. child: Padding(
  47. padding: const EdgeInsets.symmetric(horizontal: 16),
  48. child: BattleBoard(
  49. card: ClipRRect(
  50. borderRadius: BorderRadius.circular(8),
  51. child: Container(
  52. color: Colors.grey,
  53. ),
  54. ),
  55. button: CustomPaint(
  56. painter: ButtonPainter(controller: _controller),
  57. child: const SizedBox.expand(),
  58. ),
  59. ),
  60. ),
  61. ),
  62. TextButton(
  63. onPressed: () {
  64. _reset();
  65. },
  66. child: const Text('重新开始'),
  67. ),
  68. ],
  69. ),
  70. ),
  71. ],
  72. ),
  73. );
  74. }
  75. }