chore: create DialogDecoration

pull/245/head
arturplaczek 3 years ago
parent e43d4dbc60
commit 019d6a7280

@ -1 +1,3 @@
library app_ui;
export 'src/dialog/dialog.dart';

@ -0,0 +1 @@
export 'dialog_decoration.dart';

@ -0,0 +1,73 @@
import 'package:app_ui/gen/gen.dart';
import 'package:flutter/material.dart';
/// {@template dialog_background}
/// A card with image background.
///
/// Requires the header [Widget] and body [Widget], which are displayed on the
/// card.
/// {@endtemplate}
class DialogDecoration extends StatelessWidget {
/// {@macro dialog_background}
const DialogDecoration({
Key? key,
required Widget header,
required Widget body,
}) : _header = header,
_body = body,
super(key: key);
final Widget _header;
final Widget _body;
@override
Widget build(BuildContext context) {
const radius = BorderRadius.all(Radius.circular(12));
const boardWidth = 5.0;
return LayoutBuilder(
builder: (context, constraints) {
final gameWidgetWidth = constraints.maxHeight * 9 / 16;
return Center(
child: SizedBox(
height: gameWidgetWidth,
width: gameWidgetWidth,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: radius,
border: Border.all(
color: Colors.white,
width: boardWidth,
),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
Assets.images.dialog.background.keyName,
),
),
),
child: Padding(
padding: const EdgeInsets.all(boardWidth - 1),
child: ClipRRect(
borderRadius: radius,
child: Column(
children: [
Expanded(
child: Center(child: _header),
),
Expanded(
flex: 4,
child: _body,
),
],
),
),
),
),
),
);
},
);
}
}

@ -0,0 +1,26 @@
// ignore_for_file: prefer_const_constructors
import 'package:app_ui/app_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('DialogDecoration', () {
testWidgets('renders header and body', (tester) async {
const headerText = 'header';
const bodyText = 'body';
await tester.pumpWidget(
MaterialApp(
home: DialogDecoration(
header: Text(headerText),
body: Text(bodyText),
),
),
);
expect(find.text(headerText), findsOneWidget);
expect(find.text(bodyText), findsOneWidget);
});
});
}
Loading…
Cancel
Save