Created
March 1, 2023 15:58
-
-
Save pingbird/9225de5e4b18cf09d8ad65679c06104f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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