gpt4 book ai didi

flutter - 如何获取文本跨度的当前偏移量?

转载 作者:行者123 更新时间:2023-12-03 04:00:54 33 4
gpt4 key购买 nike

我正在开发“在文档中搜索”应用程序。我想在输入单词时自定义滚动 View 自动滚动到搜索到的单词。
我将文档拆分为一堆文本跨度。我如何只获得其中之一的补偿。那有可能吗?

我试过了但是没用

    with AutomaticKeepAliveClientMixin<WordViewPage> {
@override
bool get wantKeepAlive => true;
String previewedText;
ScrollController scrollController;
List<String> splitted = [''];
Color customColor = Colors.transparent;
@override
void initState() {
super.initState();
loadAsset().then((String loadedString) {
setState(() {
previewedText = loadedString;
splitter();
});
});
}

@override
Widget build(BuildContext context) {
super.build(context);
List<Widget> he = [wordFile()];
return Scaffold(
body: CustomScrollView(
controller: scrollController,
slivers: <Widget>[
SliverAppBar(
automaticallyImplyLeading: false,
title: searchBar(),
centerTitle: true,
backgroundColor: Color(0xfffc3b398),
),
SliverPadding(
padding: EdgeInsets.all(10),
sliver: SliverList(
delegate: SliverChildListDelegate(he),
),
)
],
));
}

Future<String> loadAsset() async {
return await rootBundle.loadString('assets/test.txt');
}

最佳答案

您可以通过 flutter 朔迷离的搜索代表来扩展类(class)

详细说明和代码:SearchDelegate

或者您可以看到我的代码并看到RichText()小部件

@override
Widget buildResults(BuildContext context){
return new FutureBuilder(
future: _getUser(query),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) => ListTile(
leading: Icon(Icons.person),
title: Text(snapshot.data[index].fName +
" " +
snapshot.data[index].lName),
title: RichText(
text: TextSpan(
text: suggestionList[index].substring(0, query.length),
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold)),
),
onTap: () {

},
),
);
}
},
);
}

关于flutter - 如何获取文本跨度的当前偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56839698/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com