practice
import "package:flutter/material.dart";
// void main() {
// runApp(
// Center(
// child: Text(
// "hello World",
// textDirection: TextDirection.ltr,
// ),
// ),
// );
// }
//The super keyword is also used to call the parent class’s methods, constructor, and properties in the child class.
//The super keyword in Dart is used to refer to the object of the immediate parent class of the current child class.
// The super keyword is also used to call the parent class's methods, constructor, and properties in the child class.
// Benefits of the "super" keyword :
// When both the parent and the child have members with the same name,
// super can be used to access the data members of the parent class.
//
// super can keep the parent method from being overridden.
//
// super can call the parent class’s parameterized constructor.
//
// The main goal of the super keyword is to avoid ambiguity between parent and subclasses with the same method name.
// Syntax :
// // To access parent class variables
// super.variable_name;
//
// // To access parent class method
// super.method_name();
// What is BuildContext?
// BuildContext is a locator that is used to track each widget in a tree and
// locate them and their position in the tree. The BuildContext of each widget is passed to their build method.
// Remember that the build method returns the widget tree a widget renders.
//
// Each BuildContext is unique to a widget. This means that the BuildContext of a widget
// is not the same as the BuildContext of the widgets returned by the widget.
class MyAppBar extends StatelessWidget {
const MyAppBar({required this.title, super.key});
final Widget title;
@override
Widget build(BuildContext context) {
return Container(
height: 56.0,
padding: EdgeInsets.symmetric(horizontal: 8.0,),
decoration: BoxDecoration(
color: Colors.blue[500],
),
child: Row(
children: [
IconButton(
icon: Icon(Icons.menu,),
tooltip: "Navigation menu",
onPressed: null,
),
Expanded(
child: title,
),
IconButton(
icon: Icon(Icons.search,),
tooltip: "Search",
onPressed: null,
),
],
),
);
}
}
class MyScaffold extends StatelessWidget {
const MyScaffold({super.key});
@override
Widget build(BuildContext context) {
return Material(
child: Column(
children: [
MyAppBar(
title: Text("Example title",
style: Theme.of(context).primaryTextTheme.titleLarge,
),
),
Expanded(
child: Center(
child: Text("Hello World!"),
),
),
],
),
);
}
}
void main() {
runApp(
MaterialApp(
title: "My App",
debugShowCheckedModeBanner: false,
home: SafeArea(
child: MyScaffold(),
),
),
);
}
Comments
Post a Comment