Complete the code to create a basic StatelessWidget named MyWidget.
class MyWidget extends StatelessWidget { @override Widget build(BuildContext context) { return [1]('Hello World'); } }
The build method must return a widget. Here, Text displays the string 'Hello World'.
Complete the code to add a constructor with a required title property to the StatelessWidget.
class MyWidget extends StatelessWidget { final String title; const MyWidget({Key? key, [1]) : super(key: key); @override Widget build(BuildContext context) { return Text(title); } }
required keyword.this.title without required.In Flutter, to require a property in a constructor, use required this.title.
Fix the error in the build method by completing the widget tree with a Scaffold and AppBar.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: [1](
title: Text(title),
),
body: Center(child: Text('Welcome')),
);
}Container or Text instead of AppBar for appBar.Text.The appBar property of Scaffold expects an AppBar widget.
Fill both blanks to create a StatelessWidget that returns a Center widget with a Text child.
class MyWidget extends StatelessWidget { @override Widget build(BuildContext context) { return [1]( child: [2]('Hello'), ); } }
Container instead of Center.Column when only one child is needed.The Center widget centers its child. The child here is a Text widget showing 'Hello'.
Fill all three blanks to create a StatelessWidget with a constructor, a title property, and a build method returning a Scaffold with AppBar and body.
class MyWidget extends StatelessWidget { final String [1]; const MyWidget({Key? key, required this.[2]) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text([3]), ), body: Center(child: Text('Body content')), ); } }
key instead of title in the Text widget.The property name, constructor parameter, and usage in Text must all be title to match.