【问题标题】:Flutter onTextScaleFactorChanged error?Flutter onTextScaleFactorChanged 错误?
【发布时间】:2018-03-22 15:25:42
【问题描述】:

我最近更新了 Flutter 和我的包,现在我遇到了这个我以前没有遇到的错误。我已经重新启动了 IntelliJ,并且正在对我的 FlutterDoctor 进行所有检查。

NoSuchMethodError: Class 'Window' has no instance setter 'onTextScaleFactorChanged='. Receiver: Instance of 'Window' Tried calling: onTextScaleFactorChanged=Closure: () => void from Function 'handleTextScaleFactorChanged':.

* 添加了 textAlign 代码 *

class NumberOnesPageState extends State<NumberOnesPage> {List names = new List();
    List numbers = new List();
    List ids = new List();
    List vidImages = new List();


    void _handleJson(value) {


      Map myMap = value; //store each map
      var titles = myMap.values;
      for (var items in titles){
        names.add(items['vidTitle']);
        numbers.add(items['Value']);
        ids.add(items['vidId']);
        vidImages.add(items['vidImage']);

      }

    }
      final fb = FirebaseDatabase.instance.reference();



      @override
      Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
              backgroundColor: Colors.amber,
              title: new Text('Number Ones',
              style: new TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black
              ),),
            ),
            body: new Container(
              child: new Center(
                  child: new Column(
                children: <Widget>[
                  new Flexible(
                      child: new FirebaseAnimatedList(
                          query: fb.child('NumberOnes').orderByChild('Value'),
                          padding: new EdgeInsets.all(15.0),
                          //sort: (a, b) => b.key.compareTo(a.key),
                          reverse: false,
                          itemBuilder: (_, DataSnapshot followerSnap,
                              Animation<double> animation, int Index) {
                            return new StreamBuilder<Event>(
                                stream: fb
                                    .child('NumberOnes')
                                    .orderByChild('Value')
                                    .onValue,
                                builder: (BuildContext context,
                                    AsyncSnapshot<Event> event) {
                                  switch (event.connectionState) {
                                    case ConnectionState.none:
                                      return new Card(
                                        child: new Text('Loading...',
                                            style: new TextStyle(
                                                fontSize: 12.0,
                                                fontWeight: FontWeight.bold,
                                                fontStyle: FontStyle.italic)),
                                      );
                                    case ConnectionState.waiting:
                                      return new Card(
                                        child: new Text('Awaiting Results...',
                                            style: new TextStyle(
                                                fontSize: 12.0,
                                                fontWeight: FontWeight.bold,
                                                fontStyle: FontStyle.italic)),
                                      );
                                    default:
                                      if (event.hasError)
                                        return new Card(
                                          child: new Text('Error: ${event.error}',
                                              style: new TextStyle(
                                                  fontSize: 12.0,
                                                  fontWeight: FontWeight.bold,
                                                  fontStyle: FontStyle.italic)),
                                        );
                                      else
                                        _handleJson(event.data.snapshot.value);
                                      return new InkWell(
                                        splashColor: Colors.blueAccent,
                                        onTap: (){
                                          Navigator.push(context,
                                              new MaterialPageRoute(builder: (_) => new Video.VideoPage()));
                                          Video.id = ids[Index];
                                          Video.title = names[Index];
                                          Video.videoImage = vidImages[Index];

                                          },
                                        child: new Card(
                                          child: new Column(
                                            children: <Widget>[
                                              new Padding(padding: new EdgeInsets.all(5.0)),
                                              new Image.network(vidImages[Index]),
                                              new Padding(padding: new EdgeInsets.all(3.0)),
                                              new Text('${numbers[Index]} MyFavKPopers Have Made This Their #1'),
                                              new Padding(padding: new EdgeInsets.all(3.0)),
                                              new Text(names[Index],
                                              style: new TextStyle(
                                                  fontSize: 18.0,
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.black),
                                              //textAlign: TextAlign.center,
                                              ),
                                              new Padding(padding: new EdgeInsets.all(5.0)),
                                            ],
                                          ),
                                        ),
                                      );
                                  }
                                });
                          }))
                ],
              )),
            ));
      }
    }

这是我的 textAlign 代码。它在升级之前没有给出任何错误,并且按预期生成了居中的文本。不确定是否是导致错误的代码。

我已经注释掉了我所有的 textAlign 函数。没有任何工作。它有效地将我锁定在我的代码库之外。

【问题讨论】:

  • 您能提供一些背景信息吗?这个方法在哪里调用?
  • @rainerwittman 就是这样。我不会在任何地方调用它。不确定它是否是实际的 Flutter 功能。我使用的最接近的文本函数是textAlign.center
  • @CharlesJr 请添加您的代码
  • @aziza 添加了 textAlign.center 代码。
  • 我无法使用您添加到问题中的代码重现错误。我会做一点研究;)

标签: intellij-idea text window flutter


【解决方案1】:

对我有用的是:

  • 卸载应用程序
  • 运行flutter upgrade
  • 运行flutter doctor
  • 通过命令行运行flutter run。 (IntelliJ 可能有效,但我已经在命令行中)

我不确定最初是什么导致了问题,但这似乎为我解决了问题。

【讨论】:

  • 谢谢。我的解决方案是删除所有文本对齐和缩放代码并重新启动 IntelliJ 并运行应用程序。之后,我将代码行放回原处,在完全重启和热重载时一切正常。也不确定是什么问题,可能需要添加到 github 问题单中。
猜你喜欢
  • 2022-10-04
  • 2021-01-06
  • 2021-11-14
  • 2022-01-07
  • 2021-05-28
  • 2019-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多