英文:
How to retrieve text value from RichText in flutter?
问题
以下是Flutter代码部分的翻译:
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(bottom: LuminaSpacing.extraTiny),
child: RichText(
key: Key('last_updated'),
textAlign: TextAlign.end,
text: TextSpan(
text: '${_localize.last_updated}: ',
style: wldTheme.textTheme.display1,
children: <TextSpan>[
TextSpan(
text: '${settingStore.lastCheckinTime}',
style: wldTheme.textTheme.body1),
],
),
),
),
以下是Appium Java代码部分的翻译:
FlutterFinder ele = new FlutterFinder(driver);
System.out.println("Last update: "+ele.byValueKey("last_update"));
// System.out.println("Last update: "+ele.byValueKey("last_update").getText()); // It waits for long duration
输出结果为:
Last update: [pro.truongsinh.appium_flutter.finder.FlutterElement@870fb657 -> unknown locator]
英文:
Here's the Flutter code:
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(bottom: LuminaSpacing.extraTiny),
child: RichText(
key: Key('last_updated'),
textAlign: TextAlign.end,
text: TextSpan(
text: '${_localize.last_updated}: ',
style: wldTheme.textTheme.display1,
children: <TextSpan>[
TextSpan(
text: '${settingStore.lastCheckinTime}',
style: wldTheme.textTheme.body1),
],
),
),
),
I'm using appium with java to automate my test cases
Here's my code:
FlutterFinder ele = new FlutterFinder(driver);
System.out.println("Last update: "+ele.byValueKey("last_update"));
// System.out.println("Last update: "+ele.byValueKey("last_update").getText()); // It waits for long duration
The output I get is
Last update: [pro.truongsinh.appium_flutter.finder.FlutterElement@870fb657 -> unknown locator]
答案1
得分: 1
你需要创建一个类似这样的控制器:var textController = TextEditingController();
,并将控制器与你的RichText小部件关联起来,使用这个控制器你可以这样获取文本的值:textController.text
。
英文:
you need to create a controller like this: var textController = TextEditingController();
and aggregate the controller to your RichText widget, with this controller you can get the value of the text like this: textController.text
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论