feat(ui): presentational booster bar
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// lib/ui/widgets/booster_bar.dart
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../game/models/booster.dart';
|
||||
|
||||
class BoosterBar extends StatelessWidget {
|
||||
const BoosterBar({super.key, required this.counts, required this.onTap});
|
||||
|
||||
final Map<BoosterType, int> counts;
|
||||
final void Function(BoosterType) onTap;
|
||||
|
||||
static const _icons = {
|
||||
BoosterType.hammer: Icons.gavel,
|
||||
BoosterType.shuffle: Icons.shuffle,
|
||||
BoosterType.lineBomb: Icons.clear_all,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
for (final t in BoosterType.values)
|
||||
_BoosterButton(
|
||||
key: ValueKey('booster_${t.name}'),
|
||||
icon: _icons[t]!,
|
||||
count: counts[t] ?? 0,
|
||||
onTap: () => onTap(t),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BoosterButton extends StatelessWidget {
|
||||
const _BoosterButton(
|
||||
{super.key, required this.icon, required this.count, required this.onTap});
|
||||
final IconData icon;
|
||||
final int count;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(icon, size: 28),
|
||||
const SizedBox(height: 2),
|
||||
Text('$count'),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:block_seasons/game/models/booster.dart';
|
||||
import 'package:block_seasons/ui/widgets/booster_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('renders three boosters with their counts', (tester) async {
|
||||
BoosterType? tapped;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
body: BoosterBar(
|
||||
counts: const {
|
||||
BoosterType.hammer: 3,
|
||||
BoosterType.shuffle: 0,
|
||||
BoosterType.lineBomb: 1,
|
||||
},
|
||||
onTap: (t) => tapped = t,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
expect(find.text('3'), findsOneWidget);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('booster_hammer')));
|
||||
expect(tapped, BoosterType.hammer);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user