TextSelectionTheme 小部件,配合TextField、SelectableText,可以设置文本选中时背景色、光标颜色、选择手柄颜色
样例
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class TextSelectionThemeDemo extends StatefulWidget{
@override
_TextSelectionThemeDemoState createState()=>_TextSelectionThemeDemoState();
}
class _TextSelectionThemeDemoState extends State<TextSelectionThemeDemo>{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text('修改选中文本样式样例'),
),
body: TextSelectionTheme(
data: TextSelectionThemeData(
selectionColor: Colors.red,//选中文字背景颜色
selectionHandleColor: Colors.cyanAccent,
cursorColor: Colors.orange,//光标颜色
),
child: Theme(
data: ThemeData(
cupertinoOverrideTheme: CupertinoThemeData(
primaryColor: Colors.green,
),
),
child: TextField(),
),
),
);
}
}