Ramil
Ramil

Reputation: 11

What does it mean in Flutter?

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

Answers (1)

pedro pimont
pedro pimont

Reputation: 3094

  1. 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)

  2. @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.

  3. 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

Related Questions