问题描述
import 'package:Flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class ButtonFile extends StatefulWidget {
@override
_ButtonFileState createState() => _ButtonFileState();
}
class _ButtonFileState extends State<ButtonFile> {
final db = FirebaseFirestore.instance;
String newPost;
final GlobalKey<FormState> _formKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('form'),),body: Padding(
padding: const EdgeInsets.all(16.0),child: Column(children: [
Form(
key: _formKey,autovalidateMode: AutovalidateMode.onUserInteraction,child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,validator: (_val) {
if (_val.isEmpty) {
return 'Please enter something';
}
return null;
},decoration: Inputdecoration(
border: OutlineInputBorder(),labelText: 'Post'),// onChanged: (String post) {
// getNewPost(post);
onChanged: (_val) {
newPost = _val;
},ElevatedButton(
onpressed: () {
db.collection('Posts').add({'post': newPost});
Navigator.pop(context);
},child: Text('Post'))
]),);
}
}
gcc中只有“normal func”输出,然后出现“Segmentation fault”。 clang 中的 "normal func" 和 "member func" 会一直输出。
我不认为这和c的生命周期有什么关系,因为很明显c并没有被销毁。同时,我也注意到用clang编译不需要-lpthread。那么,有人可以告诉我问题是什么吗?非常感谢!
解决方法
虽然 c
是“永不销毁”,但 FuncDetach
的参数是对为纯右值参数(指向成员的指针和指针,分别),并且当调用返回时,它们的按引用捕获变得无效(它们可能一直存在到完整表达式的结尾,但这与此处相同)。未定义行为未定义。