Codelab

92 views
Skip to first unread message

Eyyüp A

unread,
Feb 14, 2021, 10:23:45 AM2/14/21
to Flutter Development (flutter-dev)
Hey Com,

i try to code in following the codelab but I get a error:

Screenshot 2021-02-14 162149.png

but the Code is copied from the codelab and should work. 

What can I do?

The link to the Codelab: Codelab


My full Code:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

final dummySnapshot = [
{"name": "Filip", "votes": 15},
{"name": "Abraham", "votes": 14},
{"name": "Richard", "votes": 11},
{"name": "Ike", "votes": 10},
{"name": "Justin", "votes": 1},
];

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Baby Names',
home: MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() {
return _MyHomePageState();
}
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Baby Name Votes')),
body: _buildBody(context),
);
}

Widget _buildBody(BuildContext context) {
// TODO: get actual snapshot from Cloud Firestore
return _buildList(context, dummySnapshot);
}

Widget _buildList(BuildContext context, List<Map> snapshot) {
return ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
);
}

Widget _buildListItem(BuildContext context, Map data) {
final record = Record.fromMap(data);

return Padding(
key: ValueKey(record.name),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(5.0),
),
child: ListTile(
title: Text(record.name),
trailing: Text(record.votes.toString()),
onTap: () => print(record),
),
),
);
}
}

class Record {
final String name;
final int votes;
final DocumentReference reference;

Record.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['name'] != null),
assert(map['votes'] != null),
name = map['name'],
votes = map['votes'];

Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);

@override
String toString() => "Record<$name:$votes>";
}

Suzuki Tomohiro

unread,
Feb 14, 2021, 10:42:48 AM2/14/21
to Eyyüp A, Flutter Development (flutter-dev)
What does the error say?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/d779f2d0-a75e-4cb7-928d-7cb7063cb087n%40googlegroups.com.

Eyyüp A

unread,
Feb 14, 2021, 10:45:01 AM2/14/21
to Flutter Development (flutter-dev)
The Error is:
Screenshot 2021-02-14 162149.png

Suzuki Tomohiro

unread,
Feb 14, 2021, 10:59:47 AM2/14/21
to Eyyüp A, Flutter Development (flutter-dev)
I remember that “snapshot.data” has recently changed from a field to a method. Can you try adding “()”?

Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data(), reference: snapshot.reference);


Eyyüp A

unread,
Feb 14, 2021, 11:12:53 AM2/14/21
to Flutter Development (flutter-dev)
Now it works, but now I get another error:
Screenshot 2021-02-14 162149.png
Screenshot 2021-02-14 171151.png

Suzuki Tomohiro

unread,
Feb 14, 2021, 11:28:19 AM2/14/21
to Eyyüp A, Flutter Development (flutter-dev)
From the error message (”on Chrome”), I see you’re not choosing iPhone or Android. Use iPhone or Android to run the codelab.

Eyyüp A

unread,
Feb 14, 2021, 12:39:19 PM2/14/21
to Flutter Development (flutter-dev)
Yes! ON my mobile it works, but why it does not work in the browser?

Manish Vlog

unread,
Feb 15, 2021, 2:26:45 AM2/15/21
to Eyyüp A, Flutter Development (flutter-dev)

Eyyüp A

unread,
Feb 15, 2021, 4:18:32 AM2/15/21
to Flutter Development (flutter-dev)
Sorry but i do not understand how this video should help me?

Suzuki Tomohiro

unread,
Feb 15, 2021, 8:06:26 AM2/15/21
to Eyyüp A, Flutter Development (flutter-dev)
why it does not work in the browser?

It’s because browser is different from Android/iOS. Browser (flutter web) requires a special setup.

Reply all
Reply to author
Forward
0 new messages