【发布时间】:2019-09-23 07:18:23
【问题描述】:
【问题讨论】:
-
第二个问题我没看懂,你想用屏幕大小动态拉伸Text吗?您可以获取屏幕宽度的值并从那里开始,这是代码:MediaQuery.of(context).size.width
-
@mirkancal 我不想拉伸文本。我想把它放在屏幕的末尾
【问题讨论】:
Flutter 已经更新,现在 cursorColor 是这样使用的:
ThemeData(
...
textSelectionTheme: TextSelectionThemeData(
cursorColor: Colors.blue, //thereby
),
),
【讨论】:
对于问题1,您可以在调用MaterialApp 时为theme 设置cursorColor 属性,如下所示
new MaterialApp(
title: "Flutter App",
theme: ThemeData(
cursorColor: Colors.red,
home: HomeScreen(),
)
【讨论】:
这在 iOS 和 Android 上都可以正常工作:
TextField(cursorColor: Colors.white)
但是,如果你喜欢在主题中设置它那么
解决方案 1 - 原始答案,最近没有经过测试,而且似乎已被弃用:
我找到了解决方案here:
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
MaterialApp(
title: "Rate your Colleagues",
theme: ThemeData(
// for iOS
cupertinoOverrideTheme: CupertinoThemeData(
primaryColor: Colors.red,
),
// for others(Android, Fuchsia)
cursorColor: Colors.red,
home: SplashScreen(),
);
...
解决方案 2 - 已编辑答案 - 未经测试 - 请注明 @i4guar
我找到了解决方案here:
MaterialApp(
title: "Rate your Colleagues",
theme: ThemeData(
textSelectionTheme: TextSelectionThemeData(
cursorColor: darkPrimarySwatchColor,
selectionColor: darkPrimarySwatchColor,
selectionHandleColor: darkPrimarySwatchColor,
),
),
home: SplashScreen(),
);
【讨论】:
cursorColor 不起作用。
textSelectionTheme。
cursorColor 现已弃用,ThemeData 改用它(适用于 iOS 和 android):
MaterialApp(
title: "Rate your Colleagues",
theme: ThemeData(
textSelectionTheme: TextSelectionThemeData(
cursorColor: darkPrimarySwatchColor,
selectionColor: darkPrimarySwatchColor,
selectionHandleColor: darkPrimarySwatchColor,
),
),
home: SplashScreen(),
);
【讨论】:
我必须将 useTextSelectionTheme 设置为 true 并为我的自定义深色主题设置 textSelectionTheme:
ThemeData _defaultDarkTheme = ThemeData.dark();
ThemeData _darkTheme = initializeDefaultLineHeight(ThemeData(
brightness: Brightness.dark,
// How to set cursor color for TextFormField
useTextSelectionTheme: true,
textSelectionTheme: _defaultDarkTheme.textSelectionTheme.copyWith(
cursorColor: Colors.grey[600]),
【讨论】:
useTextSelection 主题是textSelectionTheme 工作所必需的。谢谢!
useTextSelectionTheme: true 成功了!
useTextSelection 主题不再需要
将 cursorColor: Colors.white, 放入TextFormField 中
【讨论】: