I'm working with Provider
provider: ^4.1.2
I had 2 pages : A, B.
Page A and B show same simple design, with below codes :
PageA.dart
class PageA extends StatelessWidget {
var songTitle = '';
@override
Widget build(BuildContext c) {
return Column(children: <Widget>[
FloatingActionButton.extended(
onPressed: () {
// LOGIC : TRANSFER TO PAGE B AFTER CLICKED BUTTON FROM PAGE A
Navigator.push(context, MaterialPageRoute(
builder: (context) => PageB()));
},
label: Text('Click'),
),
),
Text('$songTitle');
// STEP 2 : while page B already got `songTitle`
// to show on UI, I want `songTitle` also update on this page A
// in the same time
]);
}
}
PageB.dart
class PageB extends StatelessWidget {
var songTitle = '';
@override
Widget build(BuildContext c) {
return Text('$songTitle');
}
@override
void initState() {
super.initState();
// LOGIC : CALL API TO GET `songTitle` TO UPDATE ON UI
api.request().then((title) {
setState(() {
this.songTitle = title;
// STEP 1 : this causes update to page B
// show `songTitle` got from api success
});
});
}
}
These codes run with no bugs.
What I want is after
Step 1
gotsongTitle
data,It will updated its data to page A (
Step 2
) and page B (Step 1
) in the same time by usingProvider
(ex.Provider.of(context)
...)
People who knows,
Please tell me,
Thank you,
UPDATED I got correct @Chichebe answer in below already.