pass value to other widget without goto page flutter code example
Example 1: get position of a widget in screen flutter
extension GlobalKeyEx on GlobalKey {
Rect get globalPaintBounds {
final renderObject = currentContext?.findRenderObject();
var translation = renderObject?.getTransformTo(null)?.getTranslation();
if (translation != null && renderObject.paintBounds != null) {
return renderObject.paintBounds
.shift(Offset(translation.x, translation.y));
} else {
return null;
}
}
}
Example 2: get position of a widget in screen flutter
Example 3: pass string to a provider flutter
class SecondPage extends StatelessWidget { final Data data; SecondPage({this.data}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(‘Constructor — second page’), ), body: Container( padding: EdgeInsets.all(12.0), alignment: Alignment.center, child: Column( children: <Widget>[ Container( height: 54.0, padding: EdgeInsets.all(12.0), child: Text(‘Data passed to this page:’, style: TextStyle(fontWeight: FontWeight.w700))), Text(‘Text: ${data.text}’), Text(‘Counter: ${data.counter}’), Text(‘Date: ${data.dateTime}’), ], ), ), ); }}
Example 4: pass string to a provider flutter
_secondPage(BuildContext context, Widget page) async { final dataFromSecondPage = await Navigator.push( context, MaterialPageRoute(builder: (context) => page), ) as Data;