How to retrieve text value from RichText in flutter?
888
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
Author by
Pavan Boro
Updated on December 17, 2022Comments
-
Pavan Boro 5 days
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 durationThe output I get is
Last update: [[email protected] -> unknown locator]-
Hemanth Raj almost 3 yearsPlease check, you are specifyingKeyand expecting element byValueKey. Try passingValueKey<String>('last_updated')instead ofKey('last_updated'). -
Pavan Boro almost 3 yearsalready tried that way too but didn't work. Also tried using semantic label too.
-
-
gegobyte over 2 yearscontroller is not defined for RichText.