Playing around with Bloc in Flutter.
In the Bloc event, I faced a problem regarding Equatable.
At first, I cannot import equatable package: import 'package:equatable/equatable.dart'; The error says:
"The part-of directive must be the only directive in a part. Try removing other directives, or moving them to the library for which this is a part".
Later on, when I create the Event and extends Equatable, the error says:
"Classes can only extend other classes. Try specifying a different superclass, or removing the extends clause".
(FYI: I put into the pubspec.yaml the equitable dependency).
I will appreciate your assistance, as always!
The part-of directive must be the only directive in a part. Try removing other directives, or moving them to the library for which this is a part.
That error message means you can't import any package from bloc_event.dart because bloc_event.dart is part of bloc_bloc.dart. Try to import the equatable package in bloc_bloc.dart. And don't forget to flutter pub get.
import 'package:equatable/equatable.dart';
part 'bloc_event.dart';
class BlocBloc ...
It's returning an error because bloc_event.dart is part of bloc_bloc.dart.
Try to:
import the equatable package in bloc_bloc.dart
import your state class,
remove all the part imports
import them normally without the part.
import 'package:equatable/equatable.dart';
class BlocBloc...
Related
After I updated the code to adapt flutter null safety the code below gaves me the error
The getter 'value' isn't defined for the type
'BehaviorSubject'.
final _brightness = BehaviorSubject<Brightness>();
...
if (_brightness.value == Brightness.light) { ... } // error is here
How to get value from BehaviorSubject then?
Using rxdart: ^0.26.0
This is because the value getter is not implemented by BehaviorSubject class this function belongs to ValueStreamExtensions file which itself is an extension method file on the ValueStream class which BehaviorSubject is implemented by if you wish to use extension function of any type in your code you should first import the extension file into to your code file in this case just add
import 'package:rxdart/src/streams/value_stream.dart';
also, note that for using the BehaviorSubject class your should import that too
import 'package:rxdart/src/subjects/behavior_subject.dart';
or directly import the main Rx library file which imports other dependencies you may wanna use in your code like this " This is the recommended way "
import 'package:rxdart/rxdart.dart';
also, BehaviorSubject itself has a getter which is called valueWrapper that holds the latest value of your subject and you can directly use this getter
here is more information about extension methods in dart
https://dart.dev/guides/language/extension-methods
The Code you provided reads like you want to get the value from a Brightness Instance which is stored in the BehaviorSubject.
https://pub.dev/documentation/rxdart/latest/rx/BehaviorSubject-class.html
A special StreamController that captures the latest item that has been added to the controller, and emits that as the first item to any new listener.
Your _brightness variable is not from type Brightness its of type BehaviorSubject.
So you have to subscribe with a listener to it and you will get the latest value which has been added to the BehaviorSubject.
I am writing UITest for my app. In some parts of the UITest, I should call functions from Main target. When I create an Object from the Class(that has the implementation of the function), I get the error "use of undeclared of type CLASSNAME". I added the Class to the Compile Source of the test target.Then I get the same error but this time for the super class.
I added Classes to the compile source again and again, till I get this error "use of undeclared of UITextField, UIColor."
UITextField and UIColor are part of UIkit, then I import UIkit to my test Class , but did not work.
Any idea how to solve it?
In generell, How should we call functions in main target from test target?
Thanks a lot.
import your target with #testable import
import XCTest
#testable import MyProject
After installing a framework into my project with Pod, I got the error message "Use of undeclared type ..." when I tried to create my own class by inheriting the class in the Library of the framework. But I can find the class in the Library by command-clicking the class in my file. Has anyone suffered from this problem before?
You need to import Former (the module of the library you are using) to use its functions.
import UIKit
import Former // <---
final class YourCell: UITableViewCell, LabelFormableRow {
...
I'm learning java and I'm told this package is provided by default, to every class, because its methods are so common. I thought I would try to import it, any way to see what would happen. I know its not practical and probably expensive but I'm curious as to why it's doesn't work from a technical point of view.
import javax.lang.*;//why doesn't this work.
javax.lang contains only a single package: model
https://docs.oracle.com/javase/7/docs/api/index.html?javax/lang/model/package-summary.html
you're not doing anything by importing this package. Maybe you're confusing it with java.lang ?
You don't need to import java.lang.*
There is one exception to the import rule. All classes in the java.lang package are imported by default. Thus you do not need to import java.lang.*; to use them without fully qualified names.
Consider the System.out.println() method we've been using since the first day of class.
System is really the java.lang.System class. This class has a public static field called out which is an instance of the java.io.PrintStream class. So when you write System.out.println(), you're really calling the println() method of the out field of the java.lang.System class.
I'm a new in Scala. I created a package object in my code:
package mypackage.spark
import scala.language.implicitConversions
import org.apache.spark.SparkContext
import mypackage.spark.SparkContextFunctions
package object spark {
implicit def toSparkContextFunctions(sc: SparkContext): SparkContextFunctions =
new SparkContextFunctions(sc)
}
I expect that when I use import mypackage.spark._, I will able to use methods from SparkContextFunctions class. This approach works for me, when I use only only one imported package object. But when I add additional import in my code. For example:
import mypackage.spark._
import com.datastax.spark.connector._
com.datastax.spark.connector._ doing the same for org.apache.spark.SparkContext class. My code stop compile and I have an error that used method is not a member of SparkContext class. When I change the order of imports the compiler starts see methods from mypackage.spark._ and stops see methods from com.datastax.spark.connector._
Maybe I missed something? Or Scala doesn't support this?
Thanks.
If you need to use two classes named SparkContext at the same time, you can alias them:
import my.package.name.{SparkContext => MySparkContext}
import some.other.package.name.{SparkContext => OtherSparkContext}
Classes from the same package you can be aliased in the same import:
import my.package.name.{SparkContext => MySparkContext, SomethingElse => MySomethingElse}
You may want to choose better names than MyXXX and OtherXXX.
The imports may conflict in two ways: either both use toSparkContextFunctions for the implicit conversion name or both provide extension methods with the same name (even if different signature).
If neither is the case, there should be no problem. If one is, change your method names, since you can't change the ones in com.datastax.spark.connector.