你好,我是一个入门的flutter开发人员,我想用我的CloudFireStore数据库中的数据做一个列表。我不知道该怎么做。如果您对我的代码有任何帮助或建议,我们将不胜感激
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:dinghy1/components/default_button.dart';
import 'package:dinghy1/services/reservations.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../../../constants.dart';
import '../../../size_config.dart';
class Body extends StatefulWidget {
@override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
static List<Map<String, dynamic>> reservations;
static Map<String, dynamic> documents;
static List<QueryDocumentSnapshot> documents2;
static int index;
bool visibility = false;
String rental = ReservationService.rental;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: SafeArea(
child: Column(
children: [
SizedBox(
height: getPropotionateScreenWidth(20),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: getPropotionateScreenWidth(20)),
child: Container(
decoration: BoxDecoration(
color: kPrimaryColor.withOpacity(0.4),
borderRadius: BorderRadius.circular(30)),
height: getPropotionateScreenHeight(75),
width: double.infinity,
child: Center(
child: Text(
"Sprawdź rezerwacje",
style: TextStyle(
fontSize: getPropotionateScreenWidth(20),
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
),
SizedBox(
height: getPropotionateScreenWidth(20),
),
DatePicker(),
SizedBox(
height: getPropotionateScreenWidth(20),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: getPropotionateScreenWidth(20)),
child: DefaultButton(
text: "Sprawdź",
press: () {
final FirebaseAuth auth = FirebaseAuth.instance;
final User user = auth.currentUser;
String uid = user.uid;
FirebaseFirestore.instance
.collection("users")
.doc(uid)
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
rental = documentSnapshot['rental'].toString();
ReservationService()
.getReservations(
rental,
_DatePickerState.selectedDate
.toString()
.split(" ")[0])
.then((QuerySnapshot docs) {
if (docs.docs.isNotEmpty) {
int i = 0;
index = docs.size - 1;
print(index);
while (i <= index) {
documents = docs.docs[i].data();
if (documents != null) {
reservations.insert(i, documents);
i++;
print(documents);
}
}
}
});
}
});
setState(() {
RentCard.name = documents['name'];
visibility = true;
});
},
),
),
SizedBox(
height: getPropotionateScreenWidth(20),
),
visibility == true
? new Padding(
padding: EdgeInsets.symmetric(
horizontal: getPropotionateScreenWidth(20)),
child: Column(
children: [
// ...List.generate(
// documents2.length,
// (index) => RentCard(reservations: reservations[0]),
// ),
],
),
)
: new Text(
'Wybierz date i naciśnij przycisk aby sprawdzić rezerwacje!')
],
),
),
);
}
}
这是正在出错的代码示例
E/flutter ( 5082): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'insert' was called on null.
E/flutter ( 5082): Receiver: null
E/flutter ( 5082): Tried calling: insert(0, _LinkedHashMap len:7)
E/flutter ( 5082): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 5082): #1 _BodyState.build.<anonymous closure>.<anonymous closure>.<anonymous closure>
package:dinghy1/…/components/body.dart:89
E/flutter ( 5082): #2 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5082): #3 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5082): #4 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter ( 5082): #5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter ( 5082): #6 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter ( 5082): #7 Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter ( 5082): #8 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter ( 5082): #9 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter ( 5082): #10 Query.get (package:cloud_firestore/src/query.dart)
package:cloud_firestore/src/query.dart:1
E/flutter ( 5082): <asynchronous suspension>
E/flutter ( 5082): #11 ReservationService.getReservations
package:dinghy1/services/reservations.dart:19
E/flutter ( 5082): #12 _BodyState.build.<anonymous closure>.<anonymous closure>
package:dinghy1/…/components/body.dart:76
E/flutter ( 5082): #13 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5082): #14 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5082): #15 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter ( 5082): #16 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter ( 5082): #17 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter ( 5082): #18 Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter ( 5082): #19 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter ( 5082): #20 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter ( 5082): #21 DocumentReference.get (package:cloud_firestore/src/document_reference.dart)
package:cloud_firestore/src/document_reference.dart:1
E/flutter ( 5082): <asynchronous suspension>
E/flutter ( 5082): #22 _BodyState.build.<anonymous closure>
package:dinghy1/…/components/body.dart:71
E/flutter ( 5082): #23 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:993
E/flutter ( 5082): #24 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:1111
E/flutter ( 5082): #25 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:183
E/flutter ( 5082): #26 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:598
E/flutter ( 5082): #27 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:287
E/flutter ( 5082): #28 BaseTapGestureRecognizer.handlePrimaryPointer
package:flutter/…/gestures/tap.dart:222
E/flutter ( 5082): #29 PrimaryPointerGestureRecognizer.handleEvent
package:flutter/…/gestures/recognizer.dart:476
E/flutter ( 5082): #34 PointerRouter.route
package:flutter/…/gestures/pointer_router.dart:106
E/flutter ( 5082): #35 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:358
E/flutter ( 5082): #36 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:338
E/flutter ( 5082): #37 RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:267
E/flutter ( 5082): #38 GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:295
E/flutter ( 5082): #39 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:240
E/flutter ( 5082): #40 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:213
E/flutter ( 5082): #41 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5082): #42 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5082): #43 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5082): #44 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter ( 5082): #45 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
E/flutter ( 5082):
这里有一条错误消息。如果有人能帮我解决这个问题我会从幸福中发疯
在dart中,我们定义列表和地图如下:
static List<Map<String, dynamic>> reservations = [];
static Map<String, dynamic> documents = {};
List<QueryDocumentSnapshot> documents2 = [];
如果您想了解更多信息,请阅读本主题关于省道中的列表。
地图基本上是一样的。
我正在尝试用flatter和laravelapi构建一个应用程序。在我开始实现功能之前,一切都很顺利。我收到此错误
当我将其更改为list时,出现以下错误: 这里是我的小部件构建: 对于API、模型和其他函数,您可以在未处理的异常中检查我的另一篇文章:键入“\u InternalLinkedHashMap”
我有这个错误,我不明白我的错误在哪里 [错误:flatter/lib/ui/ui\u dart\u state.cc(166)]未处理的异常:NoSuchMethodError:对null调用了getter“output”。E/颤振(16491):接收器:空E/颤振(16491):尝试调用:输出 这个错误引用了这个函数,但是我没有错误语法 这就是我所说的 有人能帮忙吗!
有人能解决这个问题吗? E/flutter(6629):尝试呼叫: createUserSusEmailAndPassword(email:"nehalt88@gmail.com",密码:"123456")E/flutter(6629):#0Object.noSuchMethod(飞镖: core-patch/object_patch.dart:63: 5)E/flutter(6629):#1Re
使用RAD v7和WebSphere AS v6.1,我收到了以下消息:; Java . lang . nosuchmethod error:org/Apache/axiom/om/omabstracfactory . getmetafactory()Lorg/Apache/axiom/om/OMMetaFactory; 其他答案(这里和这里)表明这是由于冲突的罐子。我已经安装了最新的RAD/WS
本文向大家介绍Angular处理未可知异常错误的方法详解,包括了Angular处理未可知异常错误的方法详解的使用技巧和注意事项,需要的朋友参考一下 写在前面 代码写得再好,始终都无法完整的处理所有可能产生异常,特别是生产环境中的应用,很大一部分是数据来自用户、远程,很难保证所有数据都按程序规定的产生。事实上,除非测试人员发现或者客户报告,否则都无法得知。因此,将应用产生的未可知异常进而上报是非常重