Skip to content

Instantly share code, notes, and snippets.

@Dieterbe
Created June 10, 2024 12:45
Show Gist options
  • Save Dieterbe/00c9d9f7d21b03cc3889361415262cc3 to your computer and use it in GitHub Desktop.
Save Dieterbe/00c9d9f7d21b03cc3889361415262cc3 to your computer and use it in GitHub Desktop.
column layout flexible sizes test
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
Widget val(int flex, Color color, String str) {
return Flexible(
flex: flex,
fit: FlexFit.tight,
child: Container(
color: color,
child: Text(str,
overflow: TextOverflow.ellipsis, textAlign: TextAlign.right)));
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({
super.key,
required this.title,
});
Widget build(BuildContext context) {
return Column(children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
val(2, Colors.white, "a"),
val(2, Colors.green, "b"),
val(6, Colors.blue, "aaa"),
val(6, Colors.yellow, "b"),
]),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
val(2, Colors.white, "123"),
val(2, Colors.green, "longword"),
val(6, Colors.blue, "aaa"),
val(6, Colors.yellow, "longword"),
]),
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment