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

  • can you please identify whats the error and at wich point you are getting this error – Ahmad Raza Dec 26 '22 at 07: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'; – Manish Nair Dec 26 '22 at 07:41
  • Please read this to how to ask question https://stackoverflow.com/help/how-to-ask – Ahmad Raza Dec 26 '22 at 07:43
  • I tried to search everywhere but I didn't get any answers. Let me just try once more and comeback – Manish Nair Dec 26 '22 at 07:46
  • your question is not clear we dont know what is error and when it is appearing – Ahmad Raza Dec 26 '22 at 07:48
  • can you please attach a screenshot? – Adil Shinwari Dec 26 '22 at 07:49
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 26 '22 at 07:52
  • - Adil Shinwari sir, I provided you the code and I am sorry that I am not able to post the screenshot over this comment. If it possible I don't know how to post Screenshot on comments. Ad if you know, please help me out. – Manish Nair Dec 26 '22 at 08:01
  • Please share your todoui() code for better understanding of your problem statement – Prashant Dec 26 '22 at 08:25

1 Answers1

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(),
    );

  }
  
  }  
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35