import 'package:flutter/material.dart';
void main() => runApp(CoolLayoutDemo());
class CoolLayoutDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: Text(
'Cool Layout Demo',
style: TextStyle(fontSize: 24),
),
centerTitle: true,
backgroundColor: Colors.blueGrey[900],
elevation: 0,
),
body: ListView(
padding: EdgeInsets.symmetric(vertical: 20),
children: [
Center(
child: Text(
'Row and Column Layout',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 28,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 80,
height: 80,
color: Colors.red,
),
Container(
width: 80,
height: 120,
color: Colors.green,
),
Container(
width: 80,
height: 60,
color: Colors.blue,
),
],
),
),
Center(
child: Text(
'Stack and Positioned Layout',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 28,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
Container(
height: 160,
color: Colors.blueGrey[900],
child: Stack(
children: [
Positioned(
top: 30,
left: 30,
child: Container(
width: 80,
height: 80,
color: Colors.red,
),
),
Positioned(
top: 60,
left: 60,
child: Container(
width: 120,
height: 40,
color: Colors.green,
),
),
Positioned(
top: 70,
left: 90,
child: Container(
width: 50,
height: 50,
color: Colors.blue,
),
),
],
),
),
Center(
child: Text(
'Expanded Layout',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 28,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
Container(
color: Colors.blueGrey[900],
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Row(
children: [
Expanded(
child: Container(
height: 60,
color: Colors.red,
),
),
Expanded(
child: Container(
height: 90,
color: Colors.green,
),
),
Expanded(
child: Container(
height: 50,
color: Colors.blue,
),
),
],
),
),
Center(
child: Text(
'GridView',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 28,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
Container(
color: Colors.blueGrey[900],
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
height: 140,
child: GridView.count(
crossAxisCount: 2,
children: List.generate(
4,
(index) => Container(
color: Colors.purple,
margin: EdgeInsets.all(8),
),
),
),
),
Center(
child: Text(
'ListView',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 28,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
Container(
color: Colors.blueGrey[900],
height: 140,
padding: EdgeInsets.symmetric(horizontal: 20),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 5,
itemBuilder: (context, index) {
return Container(
width: 70,
color: index % 2 == 0 ? Colors.orange : Colors.teal,
margin: EdgeInsets.symmetric(horizontal: 8),
);
},
),
),
],
),
),
);
}
}
Complete implementation