Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created November 16, 2021 19:01
Show Gist options
  • Save pingbird/98309f1bc82c475cfbb160e9fd57ff50 to your computer and use it in GitHub Desktop.
Save pingbird/98309f1bc82c475cfbb160e9fd57ff50 to your computer and use it in GitHub Desktop.
import 'dart:math';
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
const redMaxWidth = 600.0;
const redMinWidth = 300.0;
const blueMaxWidth = 200.0;
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: LayoutBuilder(
builder: (context, constraints) {
final rowWidth = constraints.maxWidth;
final blueWidth = max(0.0, min(blueMaxWidth, rowWidth - redMinWidth));
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Flexible(
child: MyWidget(color: Colors.red, width: redMaxWidth),
),
MyWidget(color: Colors.blue, width: blueWidth),
],
);
}
),
),
);
}
}
class MyWidget extends StatelessWidget {
final Color color;
final double width;
const MyWidget({Key? key, required this.color, required this.width}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(8.0),
),
height: 100.0,
width: width,
child: SizeOverlay()
);
}
}
class SizeOverlay extends StatelessWidget {
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return SizedBox.expand(
child: Align(
child: Text(
'${constraints.maxWidth}',
style: const TextStyle(fontSize: 24.0),
),
),
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment