Last active
July 17, 2019 19:23
-
-
Save datafoya/579d215abcbea78d192fcdeeb6cccde1 to your computer and use it in GitHub Desktop.
Widget layout
This file contains hidden or 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_web/material.dart'; | |
| import 'package:flutter_web_test/flutter_web_test.dart'; | |
| import 'package:flutter_web_ui/ui.dart' as ui; | |
| // MyWidget displays a silver, horizontal box | |
| // StatelessWidget indicates the UI is built from fixed data | |
| class MyWidget extends StatelessWidget { | |
| @override | |
| // BuildContext enables parent-child relationships between widgets | |
| Widget build(BuildContext context) { | |
| // Row is a parent widget to the BlueBox widget | |
| return Row( | |
| children: [ | |
| // BlueBox is a child widget to the Row widget | |
| BlueBox(), | |
| ], | |
| ); | |
| } | |
| } | |
| // BlueBox displays a blue square | |
| class BlueBox extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| // Container enables customizable widgets | |
| return Container( | |
| width: 50, | |
| height: 50, | |
| decoration: BoxDecoration( | |
| color: Colors.blue, | |
| border: Border.all(), | |
| ), | |
| ); | |
| } | |
| } |
This file contains hidden or 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
| 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 a 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.children.length != 1 || row.children.any((w) => w is! BlueBox)) { | |
| _result(false, ['The Row should have one child, a BlueBox widget.']); | |
| return; | |
| } | |
| _result(true, ['A Row with one BlueBox widget.']); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment