Skip to content

Instantly share code, notes, and snippets.

@iamEtornam
Created October 2, 2022 11:24
Show Gist options
  • Save iamEtornam/e36d8d3cf7e47eb6bf417f0c63481cf9 to your computer and use it in GitHub Desktop.
Save iamEtornam/e36d8d3cf7e47eb6bf417f0c63481cf9 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class MediaQueryExample extends StatelessWidget {
const MediaQueryExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final size = .of(context).size;
return Scaffold(
appBar: AppBar(title: const Text('MediaQuery Example')),
body: Column(
children: [
if (size.width < 400) ...{
Container(
height: size.height,
color: Colors.red,
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 16),
child: const Center(child: Text('mobile view'))),
} else ...{
Row(
children: [
Container(
width: size.width / 4,
height: size.height,
color: Colors.red,
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 16),
child: const Center(child: Text('Side navigation'))),
Expanded(
child: Container(
width: size.width,
height: size.height,
color: Colors.blue,
child: const Center(child: Text('main view')),
))
],
)
}
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment