点击事件

This commit is contained in:
toly
2023-05-01 19:31:47 +08:00
parent 66b3a7946a
commit 2b438bbbbe
2 changed files with 22 additions and 5 deletions

View File

@@ -2,15 +2,19 @@ import 'package:flutter/material.dart';
class MuyuAssetsImage extends StatelessWidget {
final String image;
final VoidCallback onTap;
const MuyuAssetsImage({super.key, required this.image});
const MuyuAssetsImage({super.key, required this.image, required this.onTap});
@override
Widget build(BuildContext context) {
return Center(
child: Image.asset(
image,
height: 200,
child: GestureDetector(
onTap: onTap,
child: Image.asset(
image,
height: 200,
),
),
);
}

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_first_station/muyu/muyu_image.dart';
@@ -12,6 +14,10 @@ class MuyuPage extends StatefulWidget {
}
class _MuyuPageState extends State<MuyuPage> {
int _counter = 0;
final Random _random = Random();
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -32,7 +38,7 @@ class _MuyuPageState extends State<MuyuPage> {
children: [
Expanded(
child: CountPanel(
count: 0,
count: _counter,
onTapSwitchAudio: _onTapSwitchAudio,
onTapSwitchImage: _onTapSwitchImage,
),
@@ -40,6 +46,7 @@ class _MuyuPageState extends State<MuyuPage> {
Expanded(
child: MuyuAssetsImage(
image: 'assets/images/muyu.png',
onTap: _onKnock,
),
),
],
@@ -52,4 +59,10 @@ class _MuyuPageState extends State<MuyuPage> {
void _onTapSwitchAudio() {}
void _onTapSwitchImage() {}
void _onKnock() {
setState(() {
_counter += 1 + _random.nextInt(3);
});
}
}