fix: calculate game hud size

pull/289/head
arturplaczek 3 years ago
parent 2e2fb2a5fc
commit e8a235913f

@ -27,36 +27,44 @@ class _GameHudState extends State<GameHud> {
@override
Widget build(BuildContext context) {
final isGameOver = context.select((GameBloc bloc) => bloc.state.isGameOver);
final gameWidgetWidth = MediaQuery.of(context).size.height * 9 / 16;
final _width = gameWidgetWidth / 1.6;
final height = _calculateHeight(context);
return _ScoreViewDecoration(
child: SizedBox(
height: _width / _ratio,
width: _width,
height: height,
width: height * _ratio,
child: BlocListener<GameBloc, GameState>(
listenWhen: (previous, current) =>
previous.bonusHistory.length != current.bonusHistory.length,
listener: (_, __) => setState(() => showAnimation = true),
child: FittedBox(
alignment: Alignment.centerLeft,
child: AnimatedSwitcher(
duration: kThemeAnimationDuration,
child: showAnimation && !isGameOver
? _AnimationView(
onComplete: () {
if (mounted) {
setState(() => showAnimation = false);
}
},
)
: const ScoreView(),
),
child: AnimatedSwitcher(
duration: kThemeAnimationDuration,
child: showAnimation && !isGameOver
? _AnimationView(
onComplete: () {
if (mounted) {
setState(() => showAnimation = false);
}
},
)
: const ScoreView(),
),
),
),
);
}
double _calculateHeight(BuildContext context) {
final height = MediaQuery.of(context).size.height * 0.09;
if (height > 90) {
return 90;
} else if (height < 60) {
return 60;
} else {
return height;
}
}
}
class _ScoreViewDecoration extends StatelessWidget {

@ -18,7 +18,7 @@ class ScoreView extends StatelessWidget {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
vertical: 2,
),
child: AnimatedSwitcher(
duration: kThemeAnimationDuration,
@ -71,9 +71,11 @@ class _ScoreText extends StatelessWidget {
Widget build(BuildContext context) {
final score = context.select((GameBloc bloc) => bloc.state.score);
return Text(
score.formatScore(),
style: Theme.of(context).textTheme.headline1,
return FittedBox(
child: Text(
score.formatScore(),
style: Theme.of(context).textTheme.headline2,
),
);
}
}

Loading…
Cancel
Save