【问题标题】:getTextBeforeCursor/getSelectedText/getTextAfterCursor on inactive InputConnection非活动 InputConnection 上的 getTextBeforeCursor/getSelectedText/getTextAfterCursor
【发布时间】: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 数据吗?

【问题讨论】:

    标签: android firebase flutter


    【解决方案1】:

    非活动 InputConnection 上的 getTextBeforeCursor 是一个警告

    获取集合文档:

    FutureBuilder<QuerySnapshot>(
      future: Firestore.instance.collection('pets').getDocuments(),
      builder: (BuildContext context, snapshot){
        switch(snapshot.connectionState){
          case ConnectionState.waiting:
            return CircularProgressIndicator();
            break;
          default :
            List <DocumentSnapshot> documents = snapshot.data.documents;
            return ListView.builder(
              shrinkWrap: true,
              physics: ClampingScrollPhysics(),
              itemCount: documents.length,
              itemBuilder: (BuildContext context, index) {
                /// define how you want to show your each documents data...
                return ListTile();
              }
            );
        }
      }
    );
    

    如果您在获取收藏时可能出错,请随时发表评论,否则接受并投票!!!

    【讨论】:

    • 感谢您的帮助,我仍然在努力收集收藏,但我为您投票。你能帮我如何在列表视图中只显示大约 20 - 30 个字符的长度吗?例如,我在 firebase 上有一个数据字符串调用“描述”,它很长,就像 This is a very long description 应该像 This is a very... 一样显示。提前谢谢!
    • 收集有什么问题?
    猜你喜欢
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 2011-12-28
    • 2020-01-10
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多