无论如何,在仍然以相同方式设置此页面样式的同时,可以在此TextField中进行复制/粘贴吗?

时间:2019-05-30 20:57:31

标签: flutter dart

我在此页面上拥有的TextField在选择文本时无法对其进行任何剪切/复制/粘贴/选择所有操作。

出现选项,但是当它们被点击时什么也没有发生。我已经确定某件事阻止了输入,并认为我已经找到了源,但是我发现源阻止了它,或者在具有此功能的情况下如何使页面看起来仍然没有什么意义。

我相信问题的根源是

Opacity(
    opacity: 1,
    child: Container(
        alignment: Alignment.bottomLeft,
        height: 90,
        padding: EdgeInsets.only(left: 20, right: 20),
        child: Text('Welcome to \nMy App'),
    ),
),

下面是我的应用程序的简化版本,用于重新创建问题。

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(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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(
      backgroundColor: Colors.white,
      body: Scaffold(
        resizeToAvoidBottomPadding: false,
        body: Container(
          color: Colors.white,
          child: ListView(children: <Widget>[
            Container(
              height: 50,
            ),
            Stack(
              children: <Widget>[
                Opacity(
                  opacity: 1,
                  child: Container(
                    alignment: Alignment.bottomLeft,
                    height: 90,
                    padding: EdgeInsets.only(left: 20, right: 20),
                    child: Text('Welcome to \nMy App'),
                  ),
                ),
                Opacity(
                  opacity: 0,
                  child: Container(),
                ),
              ],
            ),
            Container(height: 15,),
            Container(
              height: 2,
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.only(left: 20, right: 20),
              child: FractionallySizedBox(
                widthFactor: 0.4,
                child: Container(color: Colors.grey,),
              ),
            ),
            Container(height: 15,),
            Container(
                height: 265,
                child: Stack(
                  children: <Widget>[
                    AnimatedOpacity(
                      opacity: 1,
                      duration: Duration(milliseconds: 200),
                      child: IgnorePointer(
                        ignoring: false,
                        child: Navigator(
                          onGenerateRoute: (RouteSettings settings) {
                            WidgetBuilder builder = (BuildContext _) => TextField();
                            return MaterialPageRoute(
                                builder: builder, settings: settings);
                          },
                        ),
                      ),
                    ),
                  ],
                )),
          ]),
        ),
      ),
    );
  }
}

当第44-52行时,我放入整个文件之前的行都被注释掉了,剪切/复制/粘贴/选择所有文件均正常进行。如果不是这样,则轻触这些选项中的任何一个都不会发生任何事情。

0 个答案:

没有答案