double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
Step 2 : from those variable you can give your widget width and height
Refer the full code, here container have made according to screen size
import 'package:flutter/material.dart';
void main() {
runApp(app());
}
class app extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
double widthVar = MediaQuery.of(context).size.width;
double heightVar = MediaQuery.of(context).size.height;
return Scaffold(
appBar: AppBar(
title: Text('Title A'),
),
body: Center(
child: Container(
width: widthVar * 0.40,
height: heightVar * 0.08,
color: Colors.blue,
),
),
);
}
}
No comments:
Post a Comment