I am expanding on the flutter_gallery example.
I try to create new Gallery Item
new GalleryItem(
title: 'Journal',
subtitle: 'Example app coding',
category: 'Apps',
routeName: JournalDemo.routeName,
buildRoute: (BuildContext context) => new JournalDemo()
),
and I imported import '../journal/journal_all.dart';
Inside I have export 'journal_demo.dart';
JournalDemo class is the same class as ListDemo, I only changed the class name and state name:
class JournalDemo extends StatefulWidget {
JournalDemo({ Key key }) : super(key: key);
static const String routeName = '/journal';
#override
JournalDemoState createState() => new JournalDemoState();
}
class JournalDemoState extends State<JournalDemo> {
.......
This is the exception I get
I/flutter : ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter : The following NoSuchMethodError was thrown building GalleryApp(dirty; state:
I/flutter : GalleryAppState(48280642)):
I/flutter : No top-level getter 'JournalDemo' declared.
I/flutter : NoSuchMethodError: method not found: 'JournalDemo'
I/flutter : Receiver: top-level
I/flutter : Arguments: [...]
I/flutter : When the exception was thrown, this was the stack:
I/flutter : #0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:184)
I/flutter : #1 kAllGalleryItems (/Users/matej/IdeaProjects/flutter/journal/lib/gallery/item.dart:51)
I/flutter : #2 kAllGalleryItems (/Users/matej/IdeaProjects/flutter/journal/lib/gallery/item.dart:45)
What should I change?
Thank you
This looks like you have either a missing import or a parse error in your code. I would recommend checking with flutter analyze as one of the posters above suggests.
No top-level getter 'JournalDemo' declared means that it cannot find the value JournalDemo in the global scope. Either because it's not imported, or because there is a parse error before this error.
Related
Minimum reproducible code:
class Parent {}
class Child extends Parent {}
class Foo<T extends Parent> {
final T t;
Foo(this.t);
Foo.one(Child child) : this(child); // Compile error
}
The argument type 'Child' can't be assigned to the parameter type 'T'.
Why can't I pass Child in redirecting constructor, in other words, why doesn't Dart know that Child satisfies T extends Parent relationship? Though I can do
void main() => Foo(Child());
Note: I'm looking for a reason as to why I can't do that. Please don't post answers to use this(child as T).
Because the code is not valid since you could do:
class Monster extends Parent {}
void main() {
final foo = Foo<Monster>.one(Child());
}
Which is a problem since Monster does extend from Parent but the constructor argument takes a Child and will then try assign this to T which is Monster.
If we do the change you don't want:
Foo.one(Child child) : this(child as T);
Then we will get the error:
type 'Child' is not a subtype of type 'Monster' in type cast
#0 new Foo.one (./bin/example1.dart:8:37)
#1 main (./bin/example1.dart:14:15)
#2 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#3 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
So you cannot say that Child can always be assigned to a variable T where T extends Parent.
I have some dart code in an interface to a Firebase Realtime Database that I need to handle setting up a stream for a particular path in my database and return all entries or use a pair of optional filter parameters to get only the required entries.
The method was originally just for the all entries requirement and works fine:
class _DatabaseStream<T> {
_DatabaseStream(
{String apiPath,
DatabaseNodeParser<T> parser,
String key = '',
String filter = ''}) {
AppDatabase _database = AppDatabase.db;
FirebaseDatabase _firebaseDatabase = _database.firebaseDatabaseInstance;
DatabaseReference _databaseReference =
_firebaseDatabase.reference().child(apiPath);
var eventStream = _databaseReference.onValue;
stream = eventStream.map((event) => parser.parse(event));
}
Stream<T> stream;
}
However when I edit the code to process the optional filter parameters I get an exception from dart. This is the updated code:
class _DatabaseStream<T> {
_DatabaseStream(
{String apiPath,
DatabaseNodeParser<T> parser,
String key = '',
String filter = ''}) {
AppDatabase _database = AppDatabase.db;
FirebaseDatabase _firebaseDatabase = _database.firebaseDatabaseInstance;
DatabaseReference _databaseReference =
_firebaseDatabase.reference().child(apiPath);
var eventStream;
if (filter == '') {
eventStream = _databaseReference.onValue;
stream = eventStream.map((event) => parser.parse(event));
} else {
// we have a filter
Query query = _databaseReference.orderByChild(key).equalTo(filter);
eventStream = query.onValue;
stream = eventStream.map((event) => parser.parse(event));
}
}
Stream<T> stream;
}
The exception reported is:
I/flutter (32750): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (32750): The following assertion was thrown building EggsPage(dirty, state: _EggsPageState#93899):
I/flutter (32750): type '_MapStream<Event, dynamic>' is not a subtype of type 'Stream<List<Egg>>'
I/flutter (32750):
I/flutter (32750): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (32750): more information in this error message to help you determine and fix the underlying cause.
I/flutter (32750): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (32750): https://github.com/flutter/flutter/issues/new?template=BUG.md
Is this really a bug that I need to report, or is there some error in my updates to the method?
I'm trying to run the aqueduct's command to generate the DB.
aqueduct db generate
but I always receive this error:
Bad state: type '_SpecialTypeMirror' is not a subtype of type 'ClassMirror' in type cast
I'm using the model like this:
import 'package:aqueduct/aqueduct.dart';
import 'package:controle_rural_api/models/Farm.dart';
class User extends ManagedObject implements _User{}
class _User {
#primaryKey
int id;
String otherThings;
bool active;
ManagedSet<Farm> farms;
}
That is the complete error:
*** Uncaught error
Bad state: type '_SpecialTypeMirror' is not a subtype of type 'ClassMirror' in type cast
**** Stacktrace
* #0 EntityBuilder._getTableDefinitionForType (package:aqueduct/src/db/managed/builders/entity_builder.dart:236:16)
* #1 new EntityBuilder (package:aqueduct/src/db/managed/builders/entity_builder.dart:16:31)
* #2 new DataModelBuilder.<anonymous closure> (package:aqueduct/src/db/managed/builders/data_model_builder.dart:7:42)
* #3 MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29)
* #4 ListIterable.toList (dart:_internal/iterable.dart:219:19)
* #5 new DataModelBuilder (package:aqueduct/src/db/managed/builders/data_model_builder.dart:7:71)
* #6 new ManagedDataModel.fromCurrentMirrorSystem (package:aqueduct/src/db/managed/data_model.dart:46:9)
* #7 MigrationBuilderExecutable.execute (<data:application/dart>:13:557)
* <asynchronous suspension>
* #8 main (<data:application/dart>:9:35)
* <asynchronous suspension>
* #9 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:296:32)
* #10 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
****
Don't look be anything about my code, but I can't generate the code, What can be?
I found the error. Was in the generics.
In the class User extends ManagedObject implements _User{} I forgot the type, so should be like this: class User extends ManagedObject<_User> implements _User{}
Is there an alternative to Navigator.push which doesn't require a context? Here is my problem.
I have a very nested and deep callstack and not each function has a BuildContext parameter. Is there any other way to get the current BuildContext than through passing it from one function to another?
test1.dart
Widget build(BuildContext) {
...
new GestureDetector(
onTap: () => foo1() // very deep callstack until it calls foo30
...
}
test2.dart
void foo30() {
// need context here like:
BuildContext context = IHopeThatExists.getCurrentContext();
// why do I need that? Navigator.push needs a context or is there an alternative? FYI: I don't need to go back to the previous page though
Navigator.push(context, ..)
}
You can use the Builder widget:
return Builder(
builder: (context) {
return RaisedButton(
onPressed: () {
Navigator.of(context).push(...);
},
...
);
},
);
If your call stack is that deep you might want to consider refactoring =D. But that aside, if you use a StatefulWidget it has a context property which is the same as what is passed to the build function.
And FYI - from the State.build docs:
The BuildContext argument is always the same as the context property
of this State object and will remain the same for the lifetime of this
object. The BuildContext argument is provided redundantly here so that
this method matches the signature for a WidgetBuilder.
I am using core-ajax-dart to fetch some data and put it in core-list-dart. And i keep getting this error. I am able to successfully pass heading which is String but I am not able to pass contacts. It fails with the following error
Exception: Uncaught Error: type 'List' is not a subtype of type
'ObservableList' of 'value'.
main page
<core-ajax-dart auto id="_ajax" url="https://polymer-contacts.firebaseio.com/{{category}}.json" handleAs="json"></core-ajax-dart>
<contacts-page class="page" id="contacts" contacts="{{contacts}}" heading="{{heading}}" flex></contacts-page>
List contacts;
ContactsPage cp = $['contacts'] as ContactsPage;
var ajax = $['_ajax'] as CoreAjax;
ajax.on["core-response"].listen((event) {
var detail = event.detail;
var response = detail['response'];
cp.contacts = response;
});
element definition
<div id="title" flex>{{heading}}</div>
<core-list-dart id="list" data="{{contacts}}">
#published List contacts;
#published String heading;
Stack trace:
Exception: Uncaught Error: type 'List' is not a subtype of type 'ObservableList' of 'value'.
Stack Trace:
#0 CoreList.data= (package:core_elements/core_list_dart.dart:48:124)
#1 main.<anonymous closure> (http://localhost:8080/index.html_bootstrap.dart:114:27)
#2 GeneratedObjectAccessorService.write (package:smoke/static.dart:114:11)
#3 write (package:smoke/smoke.dart:34:40)
#4 _updateNode (package:polymer/src/instance.dart:1412:16)
#5 _convertAndCheck (package:polymer_expressions/polymer_expressions.dart:302:16)
#6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#8 _DelayedData.perform (dart:async/stream_impl.dart:595)
#9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:711)
#10 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#11 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#12 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#13 _handleMutation (dart:html:41817)
Almost full source
The data attribute of <core-list-dart> requires an ObservableList instead of List.
What you can do is to change the field to a getter/setter where a passed List is automatically converted to a ObservableList like
class Model extends Object with Observable {
// or class SomeElement extends PolymerElement {
ObservableList _contacts;
#observable ObservableList get contacts => _contacts;
set contacts(List contacts) {
final old = _contacts;
if(contacts is ObservableList) {
_contacts = contacts;
}
_contacts = toObservable(contacts);
notifyPropertyChange(#contacts, old, _contacts);
}
}