Jebessa Dejene
Jebessa Dejene

Reputation: 61

Error: Couldn't find constructor 'ThemeData'

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',

      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    
    return Scaffold(
      appBar: AppBar(
    
        title: Text(widget.title),
      ),
      body: Center(
       
        child: Column(
        
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
    

The error is shown below. This error is not only for this app. In all codes, the error shown below is displayed when I try to run the code.

    ../../../../app/flutter/packages/flutter/lib/src/material/theme_data.dart(240,11): error G90CBB506: The name of a constructor must match the name of the enclosing class. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
lib/main.dart(6,28): error GF7CA4DBF: Couldn't find constructor 'ThemeData'. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
../../../../app/flutter/packages/flutter/lib/src/material/snack_bar.dart(450,75): error GF7CA4DBF: Couldn't find constructor 'ThemeData'. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
../../../../app/flutter/packages/flutter/lib/src/material/theme_data.dart(927,12): error GF7CA4DBF: Couldn't find constructor 'ThemeData'. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
../../../../app/flutter/packages/flutter/lib/src/material/theme_data.dart(952,32): error GF7CA4DBF: Couldn't find constructor 'ThemeData'. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
../../../../app/flutter/packages/flutter/lib/src/material/theme_data.dart(958,31): error GF7CA4DBF: Couldn't find constructor 'ThemeData'. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(245,5): error MSB8066: Custom build for 'C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\CMakeFiles\8c26996d31721dd8e16c4d3086d88a31\flutter_windows.dll.rule;C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\CMakeFiles\44b2ac0b613f8eecec5611123150db21\flutter_assemble.rule;C:\Users\JEBA\Documents\edu\3rd\flutter\form\windows\flutter\CMakeLists.txt' exited with code 1. [C:\Users\JEBA\Documents\edu\3rd\flutter\form\build\windows\flutter\flutter_assemble.vcxproj]
Building Windows application...                                         
Exception: Build process failed.

enter image description hereFlutter run, displays this error. The code is initially generated counter app.

I have tried flutter clean and flutter pub get. but it doesn't work. and I have tried to run the app on different devices. All attempts I have tried is failed.

Upvotes: 1

Views: 2749

Answers (1)

Hiwot Derese
Hiwot Derese

Reputation: 26

Follow this steps:

  1. Go to theme_data.dart by clicking ctrl + the error in the
    Debug Console.

  2. Change the name FThemeData to ThemeData as shown [1]: https://i.sstatic.net/LgPR5.jpg

  3. Save and run your code

Upvotes: 0

Related Questions