Home > front end >  The name of a constructor must match the name of the enclosing class
The name of a constructor must match the name of the enclosing class

Time:01-19

FAILURE: Build failed with an exception.

  • Where: Script 'D:\Coding\flutter_windows_3.3.10-stable\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1159

  • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'D:\Coding\flutter_windows_3.3.10-stable\flutter\bin\flutter.bat'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

final Map<String, dynamic> hotel; const HotelScreen({Key? key, required this.hotel}) : super (key: key);

CodePudding user response:

The constructor name has to be the same as the name of the class.

Is your HotelScreen class respect this syntax ?

class HotelScreen extends StatelessWidget {
  final Map<String, dynamic> hotel;
  const HotelScreen({
    Key? key,required this.hotel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

CodePudding user response:

the constructor should always have the same name as the class

does the name of your constructor match the name of the enclosing class ?

example :

public class Sample{
   public Sample(){ // same name as the class
      System.out.println("This is a constructor");
   }
   public static void main(String args[]){
      Sample obj = new Sample();
   }
}
  • Related