Text
Text(
'Text Content',
style: TextStyle(
fontSize: 24.0, // 字体大小
color: Colors.blue, // 文本颜色
fontWeight: FontWeight.bold, // 字体粗细
maxLines: 2, // 最大行数
overflow: TextOverflow.ellipsis, // 当文本超出指定的最大行数时的处理方式
textAlign: TextAlign.center,
),
)
TextButton
TextButton(
onPressed: () {},
style: TextButton.styleFrom(
foregroundColor: Colors.blue, // 设置文本颜色和水波纹颜色
backgroundColor: Colors.grey[200], // 背景颜色
textStyle: const TextStyle(fontSize: 18), // 文本样式
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0), // 圆角半径为4
),
),
child: const Text('自定义样式的按钮'),
)
TextField
TextField(
decoration: const InputDecoration(hintText: '请输入内容'),
onChanged: (value) {
print('输入的内容为:$value');
myController.textFieldValue.value = value; // 更新控制器中的值
},
);
class MyController extends GetxController {
var textFieldValue = ''.obs; // 使用 .obs 创建可观察的字符串
}
final MyController myController = Get.put(MyController()); // 初始化控制器
Obx(() => Text("您输入的内容是: ${myController.textFieldValue.value}")) // 显示当前输入的内容