Skip to content

Instantly share code, notes, and snippets.

@srix55
Created May 20, 2021 15:58
Show Gist options
  • Save srix55/2f91cfc410291f9b5fd257b67f6879b5 to your computer and use it in GitHub Desktop.
Save srix55/2f91cfc410291f9b5fd257b67f6879b5 to your computer and use it in GitHub Desktop.
Issue in setting minimum width for a container in flutter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: GridView.count(
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
alignment: Alignment.center,
child: Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
height: 300,
width: 300,
padding: const EdgeInsets.all(8),
child: const Text("He'd have you all unravel at the"),
color: Colors.teal[100],
),
),
Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
alignment: Alignment.center,
child: Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
height: 300,
width: 300,
padding: const EdgeInsets.all(8),
child: const Text('Heed not the rabble'),
color: Colors.teal[200],
),
),
Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
alignment: Alignment.center,
child: Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
height: 300,
width: 300,
padding: const EdgeInsets.all(8),
child: const Text('Sound of screams but the'),
color: Colors.teal[300],
),
),
Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
alignment: Alignment.center,
child: Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
height: 300,
width: 300,
padding: const EdgeInsets.all(8),
child: const Text('Who scream'),
color: Colors.teal[400],
),
),
Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
alignment: Alignment.center,
child: Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
height: 300,
width: 300,
padding: const EdgeInsets.all(8),
child: const Text('Revolution is coming...'),
color: Colors.teal[500],
),
),
Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
alignment: Alignment.center,
child: Container(
constraints: BoxConstraints(minWidth: 300, minHeight: 300, maxWidth: 300, maxHeight: 300),
height: 300,
width: 300,
padding: const EdgeInsets.all(8),
child: const Text('Revolution, they...'),
color: Colors.teal[600],
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment