【问题标题】:flutter: textDirection in textfield does not work颤动:文本字段中的 textDirection 不起作用
【发布时间】:2019-07-13 12:55:13
【问题描述】:

here is the result picture

飞镖代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(
      child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/login.jpg"),
            fit: BoxFit.fitHeight,
          ),
        ),
        child: Center(
          child: TextField(
            decoration: InputDecoration(
              border: InputBorder.none,
              hintText: 'Please enter a search term1',
            ),
            textDirection: TextDirection.ltr,
          ),
        ),
      ),
    );
  }
}

虽然我已经为 TextField 提供了 textDirection 参数,但它仍然告诉

I/flutter (5806):未找到方向性小部件。

I/flutter (5806):TextField 小部件需要 Directionality 小部件祖先。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    我想知道您是否需要指定textDirection。这可能不是必需的,因为您使用的是 Material 小部件。 “...当使用 MaterialApp 小部件时,这会为您处理好,...”来自https://flutter.io/docs/development/ui/widgets-intro

    但我发现另一个 SO 答案 (https://stackoverflow.com/a/49689947/4794396) 建议尝试包装小部件,例如:

    new Directionality(
         textDirection: TextDirection.ltr,
         child: // your textField here?
         ....
         ....
    

    希望这会有所帮助。

    【讨论】:

    • 如果您将文本字段包装在 Directionality 小部件中,则此方法有效。
    • 那么,为什么TextField中的textDirection本身不起作用,是不是bug?
    • @JianmingWan 能否为您的原始实现添加截图?
    猜你喜欢
    • 2022-10-16
    • 2022-06-30
    • 1970-01-01
    • 2015-08-24
    • 2018-02-04
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 2015-12-24
    相关资源
    最近更新 更多