Coder Social home page Coder Social logo

flutter-projects's Introduction

Flutter Projects

Flutter Projects

This is the code repository for Flutter Projects, published by Packt.

A practical, project-based guide to building real-world cross-platform mobile applications and games

What is this book about?

Flutter is a modern reactive mobile framework that removes a lot of the complexity found in building native mobile apps for iOS and Android. With Flutter, developers can now build fast and native mobile apps from a single codebase.

This book covers the following exciting features:

  • Design reusable mobile architectures that can be applied to apps at any scale
  • Get up to speed with error handling and debugging for mobile application development
  • Apply the principle of ‘composition over inheritance’ to break down complex problems into many simple problems
  • Update your code and see the results immediately using Flutter’s hot reload
  • Identify and prevent bugs from reappearing with Flutter’s developer tools
  • Manage an app's state with Streams and the BLoC pattern
  • Build a simple web application using Flutter Web

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

void main() {
var name = "Dart";
print ("Hello $name!");
}

Following is what you need for this book: This book is for mobile developers and software developers who want to learn Flutter to build state-of-the-art mobile apps. Although prior experience with Dart programming or Flutter is not required, knowledge of object-oriented programming (OOP), data structures and software design patterns will be beneficial.

With the following software and hardware list you can run all code files present in the book (Chapter 1-11).

Software and Hardware List

Chapter Software required OS required
1-11 Flutter 1.12.13, Dart 2.7.2, Git, Windows, Mac OS X, and Linux (Any)
Android Studio 3.6.1, VS Code

Errata

  • Page 25, Section: Using getters and setters (code snippet line 5 and 6): clark.age = 30; should be clark_age = 30; and print ('${clark.name} ${clark.surname} ${clark.age}'); should be print ('${clark.name} ${clark.surname} ${clark_age}');

Related products

Get to Know the Author

Simone Alessandria wrote his first program when he was 12: it was a text-based fantasy game for the Commodore 64. A few years later, he is now a trainer (MCT), author, speaker, passionate software architect, and always a proud coder. He has published several courses on Dart and Flutter on Pluralsight. His mission is to help developers achieve more through training and mentoring.

Suggestions and Feedback

Click here if you

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781838647773

flutter-projects's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter-projects's Issues

Ch 7: runtime error in EventDetails.fromMap constructor

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)

code outdated as of late 2021

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.

Chapter 5 variable type

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).

Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform

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;

Chapter 6, Flutter type 'List<ShoppingList>' is not a subtype of type 'int'

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'

ch2 code on oreily.com book is wildly different

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.

ch06: The showData() method in build() causes repeated calls

When I added print(shoppingList.length); this sentence to showData(), such as the following code:

The showData() method in build():

Widget build(BuildContext context) {
showData();
return Scaffold(

showData() source code:

Future showData() async {
await helper.openDb();
shoppingList = await helper.getLists();
setState(() {
shoppingList = shoppingList;
});
}

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?

The Code is different from what was taught in the book.

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

};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.