Öğrenme amaçlı yaptığım bir telefon rehberi uygulamasında yazdığım kodlarda, Hepsini tek tek kontrol etitğim halde, bu hatadan kurtulamadım: The getter ‘isEmpty’ was called on null.
Receiver: null
Tried calling: isEmpty hatası alıyorum, hata fotorğaf çekip ilgili kişiyle eşleştirmeye çalıştığımda ortay açıkıyor, if içerisine de almama rağmen çözümü bulamadım. Bana yardımcı olabilir misiniz?
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'model/contact.dart';
class AddContactPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Contact.contacts.add(Contact(name: "Test", phoneNumber: "0555 555 15 21"));
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Add New Contact"),
),
body: SingleChildScrollView(child: AddContactForm()),
);
}
}
class AddContactForm extends StatefulWidget {
@override
_AddContactFormState createState() => _AddContactFormState();
}
class _AddContactFormState extends State<AddContactForm> {
final _formKey = GlobalKey<FormState>();
File _file;
@override
Widget build(BuildContext context) {
String name;
String phoneNumber;
return Column(
children: [
Stack(children: [
Image.asset(
_file == null ? "assets/images/person-male--v2.png" : _file.path,
fit: BoxFit.cover,
width: double.infinity,
height: 250,
),
Positioned(
bottom: 8,
right: 8,
child: IconButton(
icon: Icon(Icons.camera_alt),
onPressed: getFile,
color: Colors.red,
),
),
]),
Padding(
padding: const EdgeInsets.all(8.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: TextFormField(
decoration: InputDecoration(hintText: "Contact Name"),
// ignore: missing_return
validator: (value) {
if (value.isEmpty) {
return "Name Required";
}
},
onSaved: (value) {
name = value;
},
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: TextFormField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(hintText: "Phone Number"),
// ignore: missing_return
validator: (value) {
if (value.isEmpty) {
return "Phone Number Required";
}
},
onSaved: (value) {
phoneNumber = value;
},
),
),
RaisedButton(
color: Colors.blue,
textColor: Colors.white,
child: Text("Submit"),
onPressed: () {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
Contact.contacts.add(Contact(
name: name,
phoneNumber: phoneNumber,
avatar: _file == null ? "" : _file.path));
var snackBar = Scaffold.of(context).showSnackBar(SnackBar(
duration: Duration(milliseconds: 300),
content: Text("$name has been saved")));
snackBar.closed.then((onValue) {
Navigator.pop(context);
});
}
},
),
],
),
),
),
],
);
}
void getFile() async {
// ignore: deprecated_member_use
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_file = image;
});
}
}