chore: create PinballButton

pull/252/head
arturplaczek 3 years ago
parent b82f67b801
commit 23e86edca7

@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
import 'package:pinball/gen/gen.dart';
/// {@template pinball_button}
/// Pinball button with onPressed [VoidCallback] and child [Widget].
/// {@endtemplate}
class PinballButton extends StatelessWidget {
/// {@macro pinball_button}
const PinballButton({
Key? key,
required this.child,
this.onPressed,
}) : super(key: key);
/// Child displayed on button.
final Widget child;
/// On pressed callback used for user integration.
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onPressed,
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.images.selectCharacter.pinballButton.keyName,
),
),
),
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 32,
vertical: 16,
),
child: child,
),
),
),
);
}
}

@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
import '../../../helpers/helpers.dart';
void main() {
const buttonText = 'this is the button text';
testWidgets('displays button', (tester) async {
await tester.pumpApp(
const Material(
child: PinballButton(
child: Text(buttonText),
),
),
);
expect(find.text(buttonText), findsOneWidget);
});
testWidgets('on tap calls onPressed callback', (tester) async {
var isTapped = false;
await tester.pumpApp(
Material(
child: PinballButton(
child: const Text(buttonText),
onPressed: () {
isTapped = true;
},
),
),
);
await tester.tap(find.text(buttonText));
expect(isTapped, isTrue);
});
}
Loading…
Cancel
Save