Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter StatefulWidget State name collision #41

Closed
torbenkeller opened this issue Apr 6, 2020 · 7 comments
Closed

Flutter StatefulWidget State name collision #41

torbenkeller opened this issue Apr 6, 2020 · 7 comments

Comments

@torbenkeller
Copy link

Since today in my Android Studio the dart compiler values the dartz import more than the material.dart import so I have to use

import 'package:dartz/dartz.dart' as dz;

when I want to use a StatefulWidget and some dartz objects or functions. Otherwise the app doesn't compile and throws this error message:

Compiler message:
lib/main.dart:31:32: Error: Expected 0 type arguments.
class _HomeWidgetState extends State<HomeWidget> {
                               ^
lib/main.dart:28:20: Error: The return type of the method 'HomeWidget.createState' is '_HomeWidgetState', which does not match the return type, 'State<StatefulWidget>', of the overridden method, 'StatefulWidget.createState'.
 - '_HomeWidgetState' is from 'package:stock_check/main.dart' ('lib/main.dart').
 - 'State' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
 - 'StatefulWidget' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
Change to a subtype of 'State<StatefulWidget>'.
  _HomeWidgetState createState() => _HomeWidgetState();



@mateusfccp
Copy link

mateusfccp commented Apr 6, 2020

I don't see this as an issue.
This is the default behavior for name conflict between packages, and there's indeed a State monad in dartz.

If your problem is having to type dz. to use dartz (or whatever prefix you chose to import dartz as), you may instead import only what you need with show/hide, like:

// Will import the entire package except for State
import 'package:dartz/dartz.dart' hide State;

or

// Will import only the name Option from dartz, everything else won't be imported
import 'package:dartz/dartz.dart' show Option;

@spebbe
Copy link
Owner

spebbe commented Apr 7, 2020

As @mateusfccp (thanks!) mentions above, Dart comes with excellent tools for dealing with name conflicts.

While I agree that it is unfortunate that there is a conflict to begin with, the name State for the specific structure in dartz is so standardized that it would be very confusing to call it anything else.

Are you ok with closing this?

@torbenkeller
Copy link
Author

@spebbe sure. I just wanted to open this so if somebody searches for this error he will find the solution.

@spebbe
Copy link
Owner

spebbe commented Apr 7, 2020

ah, ok!

@spebbe spebbe closed this as completed Apr 7, 2020
@Peng-Qian
Copy link

personally, I think it would be nice if dartz could avoid the name conflicts since lots of flutter developers are using the nice plugin. 👍

It a little bit annoying to use a prefix or hide/show (prefix will cause the syntax longer and all of them need a manually fix for every import). 😁

@mateusfccp
Copy link

I don't think so. I hardly use StatefulWidgets, but even when I use, my logic is decoupled of my UI, so I won't use dartz and flutter/widgets in the same file.

@Peng-Qian
Copy link

You are absolutely right, UI should be decoupled of logic. The reason I suggest here is that if we apply dartz to value object (DDD), Either() will frequently appear to UI layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants