Skip to content

Instantly share code, notes, and snippets.

@datafoya
Last active July 27, 2019 11:11
Show Gist options
  • Save datafoya/def3c5c3c68459b5bb4bdfed58f5d024 to your computer and use it in GitHub Desktop.
Save datafoya/def3c5c3c68459b5bb4bdfed58f5d024 to your computer and use it in GitHub Desktop.
mainAxisSize.max
import 'package:flutter_web/material.dart';
import 'package:flutter_web_test/flutter_web_test.dart';
import 'package:flutter_web_ui/ui.dart' as ui;
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.max,
children: [
BlueBox(),
BlueBox(),
BlueBox(),
],
);
}
}
class BlueBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(),
),
);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child: Container(
color: Color(0xffeeeeee),
child: Center(
child: Container(
child: MyWidget(),
color: Color(0xffcccccc),
),
),
),
);
}
}
Future<void> main() async {
await ui.webOnlyInitializePlatform();
runApp(MyApp());
final controller = LiveWidgetController(WidgetsBinding.instance);
final rows = controller.widgetList(find.byType(Row));
if (rows.length == 0) {
_result(false, ['Couldn\'t find Row!']);
return;
}
if (rows.length > 1) {
_result(false, ['Found ${rows.length} Rows, rather than just one.']);
return;
}
final row = rows.first as Row;
if (row.mainAxisSize != MainAxisSize.max) {
_result(false, ['Good. But try setting mainAxisSize to MainAxisSize.max.']);
return;
}
if (row.children.length != 3 || row.children.any((w) => w is! BlueBox)) {
_result(false, ['Row should have three children, all BlueBox widgets.']);
return;
}
_result(true, ['Nice! MainAxisSize.max is the default enum.']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment