Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I getting dart:html not found?

I am trying to make a quiz app and the app is running perfectly but there is this passive error
lib/main.dart:4:8: Error: Not found: ‘dart:html’
import ‘dart:html’;

Here is my code

import 'package:flutter/material.dart';
import 'dart:html';


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

List questionBank = [...];

class QuizApp extends StatefulWidget {
  @override
  State<QuizApp> createState() => _MyAppState();
}

class _MyAppState extends State<QuizApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int _currentQuestion = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "Quiz App",
          style: TextStyle(
            fontSize: 22,
            fontWeight: FontWeight.bold,
            color: Colors.black87,
          ),
        ),
        centerTitle: true,
        backgroundColor: Colors.lightBlueAccent.withOpacity(0.8),
      ),
      backgroundColor: Colors.lightBlueAccent.withOpacity(0.8),
      body: Builder(
        builder: (BuildContext context) {
          return Container(
            child: Column(
              children: [
                Center(
                    child: Image.asset(
                      "images/quiz_icon_3.png",
                      height: 265,
                    )),
                Container(
                  height: 120,
                  width: 350,
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.black87, width: 1.5),
                    borderRadius: BorderRadius.circular(22),
                  ),
                  child: Center(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Text(
                          questionBank[_currentQuestion].questionText,
                          style: TextStyle(
                            fontSize: 18.5,
                            color: Colors.black87,
                          ),
                        ),
                      )),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    ElevatedButton(
                      onPressed: () => _checkAnswer(true, context),
                      child: Text(
                        "True",
                        style: TextStyle(
                          fontSize: 20.5,
                          fontWeight: FontWeight.bold,
                          color: Colors.black87,
                        ),
                      ),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.blueGrey.shade700,
                      ),
                    ),
                    ElevatedButton(
                      onPressed: () => _checkAnswer(false, context),
                      child: Text(
                        "False",
                        style: TextStyle(
                          fontSize: 20.5,
                          fontWeight: FontWeight.bold,
                          color: Colors.black87,
                        ),
                      ),
                      style: ElevatedButton.styleFrom(
                          backgroundColor: Colors.blueGrey.shade700),
                    ),
                    ElevatedButton(
                      onPressed: () => setState(() {
                        _nextQuestion();
                      }),
                      child: Icon(
                        Icons.arrow_forward_ios,
                        color: Colors.black87,
                      ),
                      style: ElevatedButton.styleFrom(
                          backgroundColor: Colors.blueGrey.shade700),
                    )
                  ],
                )
              ],
            ),
          );
        }
      ),
    );
  }

  _nextQuestion() {
    if (_currentQuestion == questionBank.length - 1) {
      _currentQuestion = 0;
    } else {
      _currentQuestion++;
    }
  }

  _checkAnswer(bool useChoice, BuildContext context) {
    if (questionBank[_currentQuestion].isTrue = useChoice) {
      var correctBar = SnackBar(content: Text("CORRECT !"));
      ScaffoldMessenger.of(context).showSnackBar(correctBar);
    } else {
      var falseBar = SnackBar(content: Text("False !"));
      ScaffoldMessenger.of(context).showSnackBar(falseBar);
    }
  }
}

class Questions {
  String questionText;
  bool isTrue;

  Questions(this.questionText, this.isTrue);
}

I have tried importing both dart:html and io, each seperate, but nothing
I suspect the error is related to the snackBar function, or the build widget I added.
Any help will be appreciated, thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

just curious.
Are you using "dart:html" for something?

I faced similar issues, and just removing

'import 'dart:html';

works for me, unless you really need it.

using import 'dart:html' in flutter – Do I need additional dependencies?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading