|
import 'dart:math'; |
|
|
|
import 'package:boxy/boxy.dart'; |
|
import 'package:flutter/material.dart'; |
|
|
|
const darkBlue = Color.fromARGB(255, 18, 32, 47); |
|
|
|
void main() { |
|
runApp(const MyApp()); |
|
} |
|
|
|
class MyApp extends StatelessWidget { |
|
const MyApp({Key? key}) : super(key: key); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return MaterialApp( |
|
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), |
|
debugShowCheckedModeBanner: false, |
|
home: const MyHomePage(), |
|
); |
|
} |
|
} |
|
|
|
class MyHomePage extends StatefulWidget { |
|
const MyHomePage({super.key}); |
|
|
|
@override |
|
State<MyHomePage> createState() => _MyHomePageState(); |
|
} |
|
|
|
class _MyHomePageState extends State<MyHomePage> { |
|
@override |
|
Widget build(BuildContext context) { |
|
return Material( |
|
child: InkWell( |
|
child: const SizedBox.expand(), |
|
onTap: () { |
|
showDialog( |
|
context: context, |
|
builder: (context) => const MyDialog(), |
|
); |
|
}, |
|
), |
|
); |
|
} |
|
} |
|
|
|
class MyDialog extends StatelessWidget { |
|
const MyDialog({super.key}); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return AlertDialog( |
|
content: Column( |
|
mainAxisSize: MainAxisSize.min, |
|
children: [ |
|
const Text( |
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', |
|
), |
|
const SizedBox(height: 16), |
|
CustomBoxy( |
|
delegate: MyOverflowBarBoxy(), |
|
children: [ |
|
ElevatedButton( |
|
onPressed: () {}, |
|
child: const Text('LOOOOOOOOOOONG'), |
|
), |
|
ElevatedButton( |
|
onPressed: () {}, |
|
child: const Text('Cancel'), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
); |
|
} |
|
} |
|
|
|
class MyOverflowBarBoxy extends BoxyDelegate { |
|
static const spacing = 8.0; |
|
static const verticalSpacing = 8.0; |
|
|
|
@override |
|
Size layout() { |
|
final child1 = children[0]; |
|
final child2 = children[1]; |
|
final child1Width = child1.render.getMaxIntrinsicWidth(double.infinity); |
|
final child2Width = child2.render.getMaxIntrinsicWidth(double.infinity); |
|
final desiredWidth = child1Width + child2Width + spacing; |
|
if (desiredWidth > constraints.maxWidth) { |
|
final childConstraints = |
|
BoxConstraints.tightFor(width: constraints.maxWidth); |
|
final child1Size = child1.layout(childConstraints); |
|
final child2Size = child2.layout(childConstraints); |
|
child2.position(Offset(0, child1Size.height + verticalSpacing)); |
|
return Size( |
|
constraints.maxWidth, |
|
child1Size.height + child2Size.height + verticalSpacing, |
|
); |
|
} else { |
|
final child1Size = |
|
child1.layout(BoxConstraints.tightFor(width: child1Width)); |
|
final child2Size = |
|
child2.layout(BoxConstraints.tightFor(width: child2Width)); |
|
child2.position(Offset(child1Width + spacing, 0)); |
|
return Size( |
|
child1Size.width + child2Size.width + spacing, |
|
max(child1Size.height, child2Size.height), |
|
); |
|
} |
|
} |
|
|
|
@override |
|
double maxIntrinsicHeight(double width) => 0; |
|
|
|
@override |
|
double minIntrinsicHeight(double width) => 0; |
|
|
|
@override |
|
double maxIntrinsicWidth(double height) => 0; |
|
|
|
@override |
|
double minIntrinsicWidth(double height) => 0; |
|
} |