packtpublishing / flutter-projects Goto Github PK
View Code? Open in Web Editor NEWGoogle Flutter Projects by Packt Publishing
License: MIT License
Google Flutter Projects by Packt Publishing
License: MIT License
When I added print(shoppingList.length);
this sentence to showData(), such as the following code:
The showData() method in build():
Flutter-Projects/ch_06/lib/main.dart
Lines 39 to 41 in 9b16f73
showData() source code:
Flutter-Projects/ch_06/lib/main.dart
Lines 97 to 103 in 9b16f73
Add print(shoppingList.length);
to showData()
Future showData() async {
await helper.openDb();
shoppingList = await helper.getLists();
// print here
print(shoppingList.length);
setState(() {
shoppingList = shoppingList;
});
}
I found that showData() is actually being called repeatedly all the time.
It seems that showData is called in build, and setState in showData will cause build to be called again, which leads to a circular call.
This should be incorrect, right? Wouldn't this lead to a waste of resources due to non-stop rebuilding?
For one the code in the book does not work.
RenderBox was not laid out: _RenderSingleChildViewport#aa1ea relayoutBoundary=up8 NEEDS-PAINT
At the end of the "completing the ui" step it has you wrap most of the project in a SingleChildScrollView which causes the error.
There is no mention of any of these variables
double sizeX = MediaQuery.of(context).size.width;
double sizeY = MediaQuery.of(context).size.height;
final spacer = Padding(padding: EdgeInsets.only(bottom: sizeY/40));
And Spacer() is used instead of spacer....
How are you going to have the initial commit of the repo be this different from the book? Seems like quite the oversite.
This is the database in Firestore: link as you can see it is exactly as it's needed;
However upon running the application from chapter 7 on "The EventDetails model class" we get
Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform error message.
The error is caused because there's a missing field 'id' in our FireStore database, but we're trying to assign it from the EventDetail.fromMap named constructor
This needs to be updated, as we as a lot of deprecated code lines, such as getDocuments() (in favor of get()), documents() (in favor of docs()) etc;
It seems that the error originates here:
EventDetail.fromMap( dynamic obj ) {
this.id = obj['id']; // <<<< CRASH
this._description = obj['description'];
this._date = obj['date'];
this._startTime = obj['start_time'];
this._endTime = obj['end_time'];
this._speaker = obj['speaker'];
this._isFavorite = obj['is_favourite'];
}
Not sure why this is happening. Any ideas?
Thanks.
Here is the stack trace:
/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Class 'QueryDocumentSnapshot' has no instance method '[]'.
Receiver: Instance of 'QueryDocumentSnapshot'
Tried calling:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 new EventDetail.fromMap (package:events/models/event_detail.dart:14:18)
#2 _EventListState.getDetailsList. (package:events/screens/event_screen.dart:60:54)
#3 MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
#4 ListIterator.moveNext (dart:_internal/iterable.dart:343:26)
#5 new List.from (dart:core-patch/array_patch.dart:38:29)
#6 new List.of (dart:core-patch/array_patch.dart:68:17)
#7 ListIterable.toList (dart:_internal/iterable.dart:211:44)
#8 _EventListState.getDetailsList (package:events/screens/event_screen.dart:60:66)
#9 _EventListState.initState (package:events/screens/event_screen.dart:31:7)
#10 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
#11 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#12 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#13 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#15 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#16 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#17 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#19 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#20 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#21 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#22 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#23 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#25 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#27 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#29 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#30 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#31 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5991:32)
#32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#33 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#34 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#35 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
#36 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#38 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4710:11)
#39 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
#40 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#41 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#42 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#43 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#44 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
it seems you forgot to remove api key)
I wish the lifespan of the book would be extended by at least keeping the example code up-to-date.
Or stop selling the book.
In the Movie class (page 169), voteAverage is given as type double; this throws an exception:
type 'int' is not a subtype of type 'double' of 'function result'
If I changed this type to var, it passes and I can see that two of the movie averages are 0 (possibly they have no ratings).
Here is my getList function:
Future<List> getLists() async {
final List<Map<String, dynamic>> maps = await db.query('lists');
// ignore: missing_return
return List.generate(maps.length, (i) {
return ShoppingList(
maps[i]['id'],
maps[i]['name'],
maps[i]['priority'],
);
});
}
I am calling it from here
showData() async {
dynamic bb;
await helper.openDb();
shoppingList = await helper.getLists();
setState(() {
shoppingList=shoppingList;
});
}
}
I am getting the error
type 'List' is not a subtype of type 'int'
Chapter 2.
You will find the below codes in the book. Using Map in place of List caused an error in the Dropdown button widget.
final Map<String, int> _measures = {
'Meters': 0,
'Kilogram': 1,
'Grams': 2,
'kilometers': 3,
'Feets': 4,
'Miles': 5,
'Pounds (libs)': 6,
'Ounces': 7
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.