【发布时间】:2021-03-23 21:41:26
【问题描述】:
我更新了我的 Firestore 包并收到此错误(“未为类型 Map List categories = document.data['listCategories'] ?? [];
TextFormField(
controller: _catController,
obscureText: false,
autocorrect: false,
onChanged: (value) {},
decoration: InputDecoration(
labelText: 'Add a new category here',
labelStyle: TextStyle(
color: Theme.of(context).primaryColor),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Theme.of(context).primaryColor),
),
suffixIcon: IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
Icons.add,
color: Theme.of(context).primaryColor,
),
onPressed: () async {
final String name = _catController.text;
DocumentReference docRef =
userCollection.doc(_uid);
DocumentSnapshot document = await docRef.get();
List categories =
document.data['listCategories'] ?? []; // <-- ERROR
if (categories.contains(name) == true) {
setState(() {
_errorMessage =
'$name has already been added';
});
} else {
userCollection.doc(_uid).update({
'listCategories':
FieldValue.arrayUnion([name])
});
_catController.text = '';
setState(() {
_errorMessage = '';
});
}
},
),
),
autovalidateMode: AutovalidateMode.always,
cursorColor: Theme.of(context).primaryColor,
maxLines: 1,
),
【问题讨论】:
标签: function flutter dart google-cloud-firestore deprecated