'Can't understand the error and how to fix it Flutter

I'm learning Flutter and i've got an error at the beggening i don't understand why.

import 'package:flutter/material.dart'; 
 
void main() => runApp(MyApp()); 
 
class MyApp extends StatelessWidget { 
 @override 
 Widget build(BuildContext context) { 
   return MaterialApp( 
     title: 'Flutter Demo1', 
     theme: ThemeData( 
       primarySwatch: Colors.blue, 
     ), 
     home: MyHomePage(title: 'Flutter Demo Home Page1'), 
     debugShowCheckedModeBanner: false, 
   ); 
 } 
} 
 
class MyHomePage extends StatefulWidget { 
 MyHomePage({Key key, this.title}) : super(key: key); 
 
 final String title; 
 
 @override 
 _MyHomePageState createState() => _MyHomePageState(); 
} 
 
class _MyHomePageState extends State<MyHomePage> { 
 int _counter = 10; 
 String _phrase = "Clic avant l'explosion :"; 
 TextStyle _tS = TextStyle( 
   color: Colors.green, 
   fontSize: 15, 
 ); 
 Color _couleur = Colors.white; 
 
 void _decrementCounter() { 
   setState(() { 
     if (_counter > 0) { 
       _counter--; 
     }  
     if (_counter == 0) { 
       _phrase = "BOUM"; 
       _tS = TextStyle( 
         color: Colors.red, 
         fontSize: 30, 
         fontWeight: FontWeight.bold, 
       ); 
       _couleur = Colors.amber; 
     } 
   }); 
 } 
 
 @override 
 Widget build(BuildContext context) { 
   return Scaffold( 
     appBar: AppBar( 
       title: Text(widget.title), 
     ), 
     body: Center( 
       child: Column( 
         mainAxisAlignment: MainAxisAlignment.center, 
         children: <Widget>[ 
           Text( 
             '$_phrase', 
             style: _tS, 
           ), 
           Text( 
             '$_counter', 
  style: Theme.of(context).textTheme.display1,
           ), 
         ], 
       ), 
     ), 
     backgroundColor: _couleur, 
     floatingActionButton: FloatingActionButton( 
       onPressed: _decrementCounter, 
       tooltip: 'Compte à rebours', 
       child: Icon(Icons.history), 
     ), 
   ); 
 } 
} 

I'm a beginner so i can't understand why there is error and how to fix it.

Thanks for your help !



Solution 1:[1]

You need to make Key nullable and add required ti title on MyHomePage constructor like:

MyHomePage({Key? key, required this.title}) : super(key: key); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney