MIF_E31211879/lib/components/cobabackground.dart

47 lines
1.1 KiB
Dart

import 'package:flutter/material.dart';
class Background extends StatelessWidget {
final Widget child;
final String backgroundImage;
const Background({
Key? key,
required this.child,
required this.backgroundImage,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
backgroundImage), // Penggunaan backgroundImage di sini
fit: BoxFit.cover,
),
),
child: child,
),
);
}
}
void main() {
runApp(
MaterialApp(
home: Background(
// Contoh penggunaan Background dengan memberikan URL gambar
backgroundImage: 'assets/images/newbackground.png', // URL gambar disini
child: Container(
// Contoh child widget
alignment: Alignment.center,
),
),
),
);
}