This repository's purpose is for people to easily navigate to different projects that I have made on my YouTube channel. It can be from creating a Form
to implementing the BLoC architecture.
New code will from now on be added here
Code for my YouTube Videos
Home Page: https://www.youtube.com/c/robertbrunhage
This repository's purpose is for people to easily navigate to different projects that I have made on my YouTube channel. It can be from creating a Form
to implementing the BLoC architecture.
New code will from now on be added here
I get this error bad state stream has already been listened to
when i added bottomNavigationBar
to FirestoreCRUDPage
. In all other pages i will use the same stream. but when i tap on bottom navigation to go to a new page i get that error, it tries to listen to the same stream again.
is there a way to prevent that?
thanks for the great work
In the project signup_screen_card in the file SignUp.dart add comma after parameter fontSize of the method buildText.
When I added more than 7 items, and I slide down the list and slide up, it shows an error
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 1059 pos 14: '_childElements.containsKey(index)': is not true.
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 470 pos 12: 'child.hasSize': is not true.
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 1059 pos 14: '_childElements.containsKey(index)': is not true.
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 470 pos 12: 'child.hasSize': is not true.
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 1059 pos 14: '_childElements.containsKey(index)': is not true.
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 470 pos 12: 'child.hasSize': is not true.
I/flutter ( 7906): Another exception was thrown: 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 1059 pos 14: '_childElements.containsKey(index)': is not true.
`import 'package:flutter/material.dart';
import 'dart:math';
import 'package:cloud_firestore/cloud_firestore.dart';
class FireStoreForm extends StatefulWidget {
@OverRide
FireStoreFormState createState() {
return FireStoreFormState();
}
}
class FireStoreFormState extends State {
final db = Firestore.instance;
final _formKey = GlobalKey();
String age;
String name;
String id;
TextFormField nameField() {
return TextFormField(
decoration: InputDecoration(
// border: InputBorder.none,
hintText: 'name',
// fillColor: Colors.grey[300],
filled: true,
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
},
onSaved: (value) => {name = value, callback(name), print(name)},
);
}
TextFormField ageField() {
return TextFormField(
decoration: InputDecoration(
// border: InputBorder.none,
hintText: 'age',
// fillColor: Colors.grey[300],
filled: true,
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
},
onSaved: (value) => {age = value, callback(age), print(age)},
);
}
@OverRide
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
decoration: InputDecoration(
// border: InputBorder.none,
hintText: 'name',
// fillColor: Colors.grey[300],
filled: true,
),
validator: (value) {
if (value.isEmpty) {
return 'no value';
} else {
return 'value';
}
},
onSaved: (value) => {
name = value
}
),
SizedBox(height: 16.0),
// ageField(),
// SizedBox(height: 16.0),
],
),
);
}
String callback(value) {
return value;
}
createData() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
DocumentReference ref = await db
.collection('CRUD')
.add({'name': '$name ๐', 'age': '$age', 'todo': randomTodo()});
setState(() => id = ref.documentID);
print(ref.documentID);
}
}
void readData() async {
DocumentSnapshot snapshot = await db.collection('CRUD').document(id).get();
print(snapshot.data);
}
void updateData(DocumentSnapshot doc) async {
await db
.collection('CRUD')
.document(doc.documentID)
.updateData({'todo': randomTodo()});
}
void deleteData(DocumentSnapshot doc) async {
await db.collection('CRUD').document(doc.documentID).delete();
setState(() => id = null);
}
String randomTodo() {
final randomNumber = Random().nextInt(4);
String todo;
switch (randomNumber) {
case 1:
todo = 'Like and subscribe ๐ฉ';
break;
case 2:
todo = 'Twitter @RobertBrunhage ๐คฃ';
break;
case 3:
todo = 'Patreon in the description ๐ค';
break;
default:
todo = 'Leave a comment ๐ค';
break;
}
return todo;
}
}
`
`
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'firestore_form.dart';
class FirestoreCRUDPage extends StatefulWidget {
@OverRide
FirestoreCRUDPageState createState() {
return FirestoreCRUDPageState();
}
}
class FirestoreCRUDPageState extends State {
Card buildItem(DocumentSnapshot doc) {
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'name: ${doc.data['name']}',
style: TextStyle(fontSize: 24),
),
Text(
'name: ${doc.data['age']}',
style: TextStyle(fontSize: 24),
),
Text(
'todo: ${doc.data['todo']}',
style: TextStyle(fontSize: 20),
),
SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FlatButton(
onPressed: () => FireStoreFormState().updateData(doc),
child: Text('Update todo',
style: TextStyle(color: Colors.white)),
color: Colors.green,
),
SizedBox(width: 8),
FlatButton(
onPressed: () => FireStoreFormState().deleteData(doc),
child: Text('Delete'),
),
],
)
],
),
),
);
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Firestore CRUD'),
),
body: ListView(
padding: EdgeInsets.all(8),
children: [
FireStoreForm(),
SizedBox(
height: 16.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
RaisedButton(
onPressed: FireStoreFormState().createData,
child: Text('Create', style: TextStyle(color: Colors.white)),
color: Colors.green,
),
RaisedButton(
onPressed: FireStoreFormState().id != null ? FireStoreFormState().readData : null,
child: Text('Read', style: TextStyle(color: Colors.white)),
color: Colors.blue,
),
],
),
SizedBox(
height: 16.0,
),
StreamBuilder(
stream: FireStoreFormState().db.collection('CRUD').snapshots(),
builder: (context, snapshot) {
if (snapshot.data.documents.length == 0) {
return Text('No Data');
} else {
return Column(
children: snapshot.data.documents
.map((doc) => buildItem(doc))
.toList());
}
},
)
],
),
);
}
}
`
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'validate' was called on null.
Receiver: nul
I have googled, most of the post said Wrap with Form, and add the global form key, but I have added, still not working...
Thanks very much for your time
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.