-5

I have an issue to solve an error which I am facing past 3 days, begin the journey in coding since months but I can't get Errors. Here is the Snippet of Todo List code.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  _MyAppState createState() => _MyAppState();
}
  // This widget is the root of your application.
  class _MyAppState extends State<MyApp>  {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "TODO",
      debugShowCheckedModeBanner: false,
      theme:  ThemeData.dark().copyWith(
        accentColor: Colors.purple,

      ), 
    home: todoui(),
    );

  }
  
  }  

And I am facing issues for showing me errors, could anyone help me out of this?

I tried to find over the forums of flutter which I thought it would be helpful, but it didn't work.

9
  • can you please identify whats the error and at wich point you are getting this error
    – Ahmad Raza
    Dec 26, 2022 at 7:36
  • I am receiving error in importing flutter package which I assumed that all default packages are successfully installed, but I was wrong. To be specific this code is not working on my system. To be specific I am getting error in, import 'package:flutter/material.dart'; Dec 26, 2022 at 7:41
  • Please read this to how to ask question stackoverflow.com/help/how-to-ask
    – Ahmad Raza
    Dec 26, 2022 at 7:43
  • I tried to search everywhere but I didn't get any answers. Let me just try once more and comeback Dec 26, 2022 at 7:46
  • your question is not clear we dont know what is error and when it is appearing
    – Ahmad Raza
    Dec 26, 2022 at 7:48

1 Answer 1

0

I see the declaration of StatefulWidget, O mean there is a base widget class and there is a State object class, but the widget class extends StatelessWidget, well this is wrong since it don't have a state:

you will need to just change the first line to this:

class MyApp extends StatefulWidget { // here
  @override
  _MyAppState createState() => _MyAppState();
}
  // This widget is the root of your application.
  class _MyAppState extends State<MyApp>  {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "TODO",
      debugShowCheckedModeBanner: false,
      theme:  ThemeData.dark().copyWith(
        accentColor: Colors.purple,

      ), 
    home: todoui(),
    );

  }
  
  }  

this is a StatefulWigdet and it will work

However if you was trying to refactor it to a StatelessWidget, then you should make it like this:

  class MyApp extends StatelessWidget  {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "TODO",
      debugShowCheckedModeBanner: false,
      theme:  ThemeData.dark().copyWith(
        accentColor: Colors.purple,

      ), 
    home: todoui(),
    );

  }
  
  }  
16
  • I just copied the code and tried to run the entire code that you have mention, I am still getting errors. is there any possibilities? Dec 26, 2022 at 13:54
  • just change the MyApp class with this code, but let the main() and the imports as they are on top of your file
    – Gwhyyy
    Dec 26, 2022 at 14:00
  • -Gwhyyy Should I need to add constructor? Because it is asking me to add that. Dec 26, 2022 at 14:47
  • can you share with me the current full code you tried again ?
    – Gwhyyy
    Dec 26, 2022 at 14:48
  • But how? is it possible to paste entire code in the comment? Dec 26, 2022 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.