Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter constructor error

Tags:

flutter

dart

I have a problem with a code snippet I tried to play with, and since I am new to dart I don't really understand the error message. Can somebody explain to me why the error message says

The constructor returns type 'dynamic' that isn't of expected type 'widget'.

and how to fix it?

like image 971
stefanmuke Avatar asked Jun 14 '17 17:06

stefanmuke


People also ask

What is constructor flutter?

Constructor is a special method of Dart class which is automatically called when the object is created. The constructor is like a function with/without parameter but it doesn't have a return type.

What is covariant in flutter?

By using the covariant keyword, you disable the type-check and take responsibility for ensuring that you do not violate the contract in practice. As you can see in the example, if you are overriding a method, its params should also be the same.

What is use of private constructor in flutter?

Private Constructor – is an exclusive instance constructor that restricts this class from being instantiated in other classes. This class is mainly used when you need to have static members only e.g static variables or static methods.


2 Answers

The class MaterialList doesn't exist. It looks like maybe you meant TwoLevelList, which is deprecated. You should try ListView instead.

like image 176
Collin Jackson Avatar answered Oct 09 '22 14:10

Collin Jackson


If you have other import statements try to use alias as some libraries may be the reason for conflict.

Example: import 'package:html/parser.dart' as parser;

like image 45
Divakar Rajesh Avatar answered Oct 09 '22 15:10

Divakar Rajesh