
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
스코어 100점씩 올라가는건 구현 완료했는데
새게임 버튼 누르면 리셋되는 기능을 어떻게 구현해야하는지 전혀 모르겠습니다
void resetGame() {
setState(() {
tryCount = 0;
score = 0;
resetCard();
});
}
void resetCard() {
List<int> cardsValue = [1, 5, 2, 6, 3, 4, 3, 2, 6, 1, 4, 5];
cardsValue.shuffle();
cards = List.generate(cardsValue.length, (index) {
return CardModel(index: index, cardValue: cardsValue[index]);
});
}
Home.dart에 이렇게 써놓고
Header(
tryCount: tryCount,
score: score,
resetGame: resetGame,
),
아래쪽 헤더에 이렇게 써놓고
Header.dart는 아래처럼 해놓았습니다
import 'package:flutter/material.dart';
class Header extends StatefulWidget {
final int tryCount;
final int score;
late Function resetGame;
Header({
super.key,
this.tryCount = 0,
this.score = 0,
required void Function() resetGame,
});
@override
State<Header> createState() => _HeaderState();
}
class _HeaderState extends State<Header> {
@override
Widget build(BuildContext context) {
return SizedBox(
height: 60,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'score',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w200,
color: Colors.black,
letterSpacing: 0,
height: 0,
),
),
Text(widget.score.toString(),
style: TextStyle(
height: 0,
fontSize: 30,
letterSpacing: -2,
fontWeight: FontWeight.bold,
color: Colors.black)),
],
)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'try count',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w200,
color: Colors.black,
letterSpacing: 0,
height: 0,
),
),
Text(widget.tryCount.toString(),
style: TextStyle(
height: 0,
fontSize: 30,
letterSpacing: -2,
fontWeight: FontWeight.bold,
color: Colors.black)),
],
)),
Expanded(
child: GestureDetector(
onTap: () {},
child: Container(
margin: EdgeInsets.only(top: 10, bottom: 10, left: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Color(0xff94BEE5),
),
child: Center(child: Text('새 게임')),
),
),
),
],
),
);
}
}
맨밑에 onTap: () {}의 중괄호 안에 이것저것 집어넣어봤는데 오작동은 고사하고 아무 반응도 없어서
어떻게 해야 되는지를 모르겠네요
힌트 좀 주실 수 있을까요
작성한 코드 및 에러 메세지
