import 'package:flutter/material.dart';
class ResponsiveWelcomeScreen extends StatelessWidget {
const ResponsiveWelcomeScreen({super.key});
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final screenWidth = size.width;
final screenHeight = size.height;
final double fontSize = screenWidth * 0.08; // 8% of screen width
final double buttonWidth = screenWidth * 0.6; // 60% of screen width
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Welcome to App!',
style: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 30),
SizedBox(
width: buttonWidth,
child: ElevatedButton(
onPressed: () {},
child: const Text('Get Started'),
),
),
],
),
),
);
}
}
This screen uses MediaQuery.of(context).size to get the device's screen width and height.
The font size for the welcome text is set to 8% of the screen width, so it scales nicely on small and large devices.
The 'Get Started' button width is set to 60% of the screen width using a SizedBox to keep it responsive.
The text and button are centered vertically and horizontally using a Column inside a Center widget.