I use setState(() {}) for assigning a value to a variable. But it's printing again and again. Why does it react like this? And how can I fix it?
Here is my code:
class Sample extends StatefulWidget {
@override
_SampleState createState() => _SampleState();
}
class _SampleState extends State<Sample> {
String _message;
String _appLink;
Firestore db = Firestore.instance;
@override
Widget build(BuildContext context) {
db.collection('share').document('0').get().then((value) {
var message = value.data['message'];
print(message);
var appLink = value.data['appLink'];
setState(() {
_message = message;
_appLink = appLink;
});
});
return Container(
child: Text('$_message $_appLink'),
);
}
}
Here is my Output:
Here _appLink value is www.facebook.com
