Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created March 1, 2023 15:58
Show Gist options
  • Save pingbird/9225de5e4b18cf09d8ad65679c06104f to your computer and use it in GitHub Desktop.
Save pingbird/9225de5e4b18cf09d8ad65679c06104f to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:boxy/boxy.dart';
import 'dart:math';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
CustomBoxy(
delegate: MyBoxyDelegate(),
children: [
Container(
color: Colors.red,
child: Text('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
),
Container(
color: Colors.blue,
child: Text('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'),
),
],
),
CustomBoxy(
delegate: MyBoxyDelegate(),
children: [
Container(
color: Colors.red,
child: Text('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
),
Container(
color: Colors.blue,
child: Text('bbbbbbbbbbbb'),
),
],
),
CustomBoxy(
delegate: MyBoxyDelegate(),
children: [
Container(
color: Colors.red,
child: Text('aaaaaaaaaaaa'),
),
Container(
color: Colors.blue,
child: Text('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'),
),
],
),
],
);
}
}
class MyBoxyDelegate extends BoxyDelegate {
@override
Size layout() {
final width = constraints.maxWidth;
final firstChild = children[0];
final secondChild = children[1];
final secondIntrinsicWidth =
secondChild.render.getMaxIntrinsicWidth(double.infinity);
final firstSize = firstChild.layout(BoxConstraints(
maxWidth: max(width / 2, width - secondIntrinsicWidth),
));
final secondSize = secondChild.layout(BoxConstraints.tightFor(
width: width - firstSize.width,
));
secondChild.position(Offset(firstSize.width, 0));
return Size(
width,
max(firstSize.height, secondSize.height),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment