颤动:文本字段中的 textDirection 不起作用

flutter: textDirection in textfield does not work

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): No Directionality widget found.

I/flutter ( 5806): TextField widgets require a Directionality widget ancestor.

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

但我发现了另一个 SO 答案 (),它建议尝试包装像这样的小部件:

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

希望对您有所帮助。