flutter positioned widget max size code example

Example 1: how to get the display size of mobile display in flutter

getHeightWidth(context){
 
    double width = MediaQuery.of(context).size.width;
 
    double height = MediaQuery.of(context).size.height;
 
    setState(() {
     heightHolder = height.roundToDouble();
     widthHolder = width.roundToDouble() ; 
    });
 
  }

Example 2: flutter set widget width to 50% o parent


  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("MediaQuery"),
      ),
      body: Container(
        width: MediaQuery.of(context).size.width * 0.5,
        height: MediaQuery.of(context).size.height * 0.5,
      ),
    );
  }

Tags:

Dart Example