-
-
Save legalcodes/c46f9a9f6c99c2c00497df5dbc0b4593 to your computer and use it in GitHub Desktop.
Create the name and title
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 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// Begin implementing the Column here. | |
} | |
} |
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 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text('Flutter McFlutter', style: Theme.of(context).textTheme.headline), | |
Text('Experienced Developer'), | |
], | |
); | |
} | |
} |
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
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
scaffoldBackgroundColor: Color(0xffeeeeee), | |
textTheme: TextTheme( | |
body1: TextStyle( | |
fontSize: 16, | |
), | |
), | |
), | |
home: Scaffold( | |
body: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Center( | |
child: Container( | |
decoration: BoxDecoration( | |
color: Color(0xffffffff), | |
border: Border.all(), | |
boxShadow: [ | |
BoxShadow( | |
blurRadius: 10, | |
color: Color(0x80000000), | |
), | |
], | |
), | |
padding: const EdgeInsets.all(8.0), | |
child: MyWidget(), | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
Future<void> main() async { | |
final completer = Completer<void>(); | |
runApp(MyApp()); | |
WidgetsFlutterBinding.ensureInitialized() | |
.addPostFrameCallback((timestamp) async { | |
completer.complete(); | |
}); | |
await completer.future; | |
final controller = LiveWidgetController(WidgetsBinding.instance); | |
// Check MyWidget starts with one Column | |
final myWidgetElement = controller.element(find.byType(MyWidget)); | |
final myWidgetChildElements = <Element>[]; | |
myWidgetElement.visitChildElements((e) => myWidgetChildElements.add(e)); | |
if (myWidgetChildElements.length != 1 || | |
myWidgetChildElements[0].widget is! Column) { | |
_result(false, ['The root widget in MyWidget\'s build method should be a Column.']); | |
return; | |
} | |
// Check Column has correct properties | |
final innerColumnElement = myWidgetChildElements[0]; | |
final innerColumnWidget = innerColumnElement.widget as Column; | |
if (innerColumnWidget.crossAxisAlignment != CrossAxisAlignment.start) { | |
_result(false, ['The Column that contains the name and title should use CrossAxisAlignment.start as its CrossAxisAlignment value.']); | |
return; | |
} | |
if (innerColumnWidget.mainAxisSize != MainAxisSize.min) { | |
_result(false, ['The Column that contains the name and title should use MainAxisSize.min as its MainAxisSize value.']); | |
return; | |
} | |
// Check inner Column has two Text children | |
if (innerColumnWidget.children.any((w) => w is! Text)) { | |
_result(false, ['The Column that contains the name and title should have two children, both Text widgets.']); | |
return; | |
} | |
// Check first Text has headline style | |
final nameText = innerColumnWidget.children[0] as Text; | |
if (nameText?.style?.fontSize != 24) { | |
_result(false, ['The Text widget for the name should use the "headline" textStyle.']); | |
return; | |
} | |
_result(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment