I need to take token before but I can using await into initState
Opened this issue · 0 comments
hguzman commented
I need to take token before but I can using await into initState
do you have any advise?
@override
void initState() {
super.initState();
final _storage = new FlutterSecureStorage();
String token = await _storage.read(key: 'token'); // <---
_cable = ActionCable.Stream(_action_cable_url, {HttpHeaders.authorizationHeader: token}); // <---
_cable.stream.listen((value) {
if (value is ActionCableConnected) {
print('ActionCableConnected');
_cable.subscribeToChannel(_channel, channelParams: {'id': 10});
} else if (value is ActionCableSubscriptionConfirmed) {
print('ActionCableSubscriptionConfirmed');
_cable.performAction(_channel, 'send_message',
channelParams: {'id': 10}, actionParams: {'body': 'hello world'});
} else if (value is ActionCableMessage) {
print('ActionCableMessage ${jsonEncode(value.message)}');
}
});
}