When I try to do this absolutely nothing happens when url is changed and setstate launched.
String previewUrl = 'https://google.com';
Widget build(BuildContext context) {
PostsViewModel viewModel = Provider.of<PostsViewModel>(context);
return WillPopScope(
onWillPop: () async {
await viewModel.resetPost();
return true;
},
child: ModalProgressHUD(
progressIndicator: circularProgress(context),
inAsyncCall: viewModel.loading,
child: Scaffold(
key: viewModel.scaffoldKey,
appBar: AppBar(
leading: IconButton(
icon: Icon(Feather.x),
onPressed: () {
viewModel.resetPost();
Navigator.pop(context);
},
),
title: Text('MyApp'),
centerTitle: true,
actions: [
InkWell(
onTap: () async {
print(controller.text);
await postToApi(viewModel.description);
controller.clear();
viewModel.resetPost();
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => TabScreen()),
);
},
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
'Post'.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15.0,
color: Theme.of(context).accentColor,
),
),
),
)
],
),
body: ListView(
children: [
AnyLinkPreview(
link: previewUrl,
displayDirection: UIDirection.UIDirectionHorizontal,
cache: Duration(hours: 1),
backgroundColor: Colors.grey[300],
errorWidget: Container(
color: Colors.grey[300],
child: Container(),
),
),
Padding(
padding: EdgeInsets.all(10),
child: Column(children: [
Container(
width: double.infinity,
child: Text(
'Link'.toUpperCase(),
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.w600,
),
),
),
TextFormField(
decoration: InputDecoration(
hintText: 'Source',
focusedBorder: UnderlineInputBorder(),
),
maxLines: null,
onChanged: (value) {
_url1 = value;
previewUrl = value;
},
),
TextButton(
child: Text("Fetch"),
onPressed:() {
setState(() {
print(previewUrl);
});
},
)
]),
),
]);
However this does not refresh the preview even though previewURL changes with setState. Any way to achieve this?
Running the latest RC as version.