Reputation: 11
1.const GreenFrog({ Key key }) : super(key: key);
,
2.@override
,
3.Widget build(BuildContext context)
what does these three things referring to?
class GreenFrog extends StatelessWidget {
const GreenFrog({ Key key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(color: const Color(0xFF2DBD3A));
}
}
Upvotes: -6
Views: 70
Reputation: 3094
GreenFrog({ Key key }) : super(key: key)
This is the constructor for the GreenFrog
class and its super constructor respectively. The super constructor is the constructor of its parent, the StatelessWidget
(see inheritance in OOP)
@override
is an annotation that indicates that this method is being overridden (since its also defined in the super class (StatelessWidget
)). This makes so that GreenFrog will have its own build method and won't use its parent build method.
Widget build(BuildContext context)
is a function/method that takes in a context
and returns a Widget
. The Flutter Framework expect your widgets to have this method defined so it can render them on the screen.
This is too much to explain in a single answer and all those questions relate to OOP (Object Oriented Programming), so you should try to understand them first. Try the documentation or some book. Here is a small and free book for beginners. It may help you.
Upvotes: 4