Skip to content

Instantly share code, notes, and snippets.

@datafoya
Last active November 19, 2019 16:33
Show Gist options
  • Save datafoya/30ccbe0fcf31cc10eafba3aea8ff0697 to your computer and use it in GitHub Desktop.
Save datafoya/30ccbe0fcf31cc10eafba3aea8ff0697 to your computer and use it in GitHub Desktop.
Create the name and title
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) {
// Begin implementing the Column here.
}
}
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 Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Flutter McFlutter', style: Theme.of(context).textTheme.headline),
Text('Experienced Developer'),
],
);
}
}
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 {
await ui.webOnlyInitializePlatform();
runApp(MyApp());
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