【发布时间】:2020-11-15 16:06:04
【问题描述】:
我遇到了颤振问题。昨天睡觉前,我的代码运行良好,它也在 firebase 上添加了数据。然后我睡着了,现在我的程序不工作了。它一直在告诉这些错误
W/IInputConnectionWrapper( 6414): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 6414): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 6414): getTextAfterCursor on inactive InputConnection
我的应用程序基本显示 2 文本字段,用户可以在其中输入宠物的姓名和年龄。当我输入宠物名称时会发生此错误,然后点击宠物年龄的文本字段并打印错误。我认为在 2 个文本字段之间切换时出现错误。但是,昨天我的应用运行良好!
我从this link 复制并修改了代码,以了解应用程序如何在 firebase 上创建、更新数据。
这里是tkshnwesper solution。但是,当我关注 tkshnwesper 时,我的程序仍然显示相同的错误。
这是我的代码:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Pets',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Register Pet'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Please Register Your Pet ",
style: TextStyle(
fontWeight: FontWeight.w200,
fontSize: 30,
fontFamily: 'Roboto',
fontStyle: FontStyle.italic)),
RegisterPet(),
]),
)),
);
}
}
class RegisterPet extends StatefulWidget {
RegisterPet({Key key}) : super(key: key);
@override
_RegisterPetState createState() => _RegisterPetState();
}
class _RegisterPetState extends State<RegisterPet> {
final _formKey = GlobalKey<FormState>();
final nameController = TextEditingController();
final ageController = TextEditingController();
final dbRef = Firestore.instance.collection("pets");
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(children: <Widget>[
Padding(
padding: EdgeInsets.all(20.0),
child: TextFormField(
controller: nameController,
decoration: InputDecoration(
labelText: "Enter Pet Name",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Enter Pet Name';
}
return null;
},
),
),
Padding(
padding: EdgeInsets.all(20.0),
child: TextFormField(
controller: ageController,
decoration: InputDecoration(
labelText: "Enter Pet Age",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please Pet Age';
}
return null;
},
),
),
Padding(
padding: EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
color: Colors.lightBlue,
onPressed: () {
if (_formKey.currentState.validate()) {
print("aaaaaaa");
dbRef.add({
"name": nameController.text,
"age": ageController.text,
}).then((_) {
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Successfully Added')));
}).catchError((onError) {
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text(onError)));
});
print("aaaoooa");
};
ageController.text = '';
nameController.text = '';
},
child: Text('Submit'),
),
RaisedButton(
color: Colors.amber,
onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => Home()),
// );
},
child: Text('Navigate'),
),
],
)),
])));
}
@override
void dispose() {
super.dispose();
ageController.dispose();
nameController.dispose();
}
}
另外,你们能帮我在模拟器上以列表的形式显示“宠物”集合的 Firebase 数据吗?
【问题讨论】: