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 over 1 year
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]
-
Hemanth Raj over 4 yearsPlease check, you are specifying
Key
and expecting element byValueKey
. Try passingValueKey<String>('last_updated')
instead ofKey('last_updated')
. -
Pavan Boro over 4 yearsalready tried that way too but didn't work. Also tried using semantic label too.
-
-
gegobyte about 4 yearscontroller is not defined for RichText.