dart

How to check auth token at entry point of flutter app

若如初见. 提交于 2021-01-29 02:22:36
问题 I need to know how to check the token at entry point of app. I have already saved that in shared preference by ` _saveToken() async { SharedPreferences prefs = await SharedPreferences.getInstance(); String token = await response.data['token']; await prefs.setString('jwt', token); } ` and I need to bypass my login screen if this jwt is not null. How can I do this? 回答1: You can copy paste run full code below You can get jwt token in main() and check jwt content is null or not in initialRoute

How to check auth token at entry point of flutter app

ぐ巨炮叔叔 提交于 2021-01-29 02:22:31
问题 I need to know how to check the token at entry point of app. I have already saved that in shared preference by ` _saveToken() async { SharedPreferences prefs = await SharedPreferences.getInstance(); String token = await response.data['token']; await prefs.setString('jwt', token); } ` and I need to bypass my login screen if this jwt is not null. How can I do this? 回答1: You can copy paste run full code below You can get jwt token in main() and check jwt content is null or not in initialRoute

How to detect if another application is open in Flutter?

送分小仙女□ 提交于 2021-01-29 02:04:12
问题 [EDITED] I want to create an application that discourages the usage of social media applications. Like if they open Instagram or something then the Flutter app will know. How would I detect if another application (Such as Instagram or Twitter) is open when my Flutter app is opened? If this is difficult to implement in Flutter, can anyone suggest some other languages or code for this functionality? Thanks!! 回答1: It is possible at least on Android. I do not program for IOS so I can't say for

How to use ByteData and ByteBuffer in flutter without mirror package

北战南征 提交于 2021-01-28 23:09:10
问题 I am trying to develop a UDP application that receives data and converts the bytes into different data types. I have the code below that works when using Dart on its own. import 'dart:io'; import 'dart:typed_data'; import 'dart:mirror'; RawDatagramSocket.bind(InternetAddress.ANY_IP_V4, 20777).then((RawDatagramSocket socket){ socket.listen((RawSocketEvent e){ Datagram d = socket.receive(); if (d == null) return; ByteBuffer buffer = d.data.buffer; DKByteData data = new DKByteData(buffer); exit

How to use ByteData and ByteBuffer in flutter without mirror package

浪子不回头ぞ 提交于 2021-01-28 23:00:59
问题 I am trying to develop a UDP application that receives data and converts the bytes into different data types. I have the code below that works when using Dart on its own. import 'dart:io'; import 'dart:typed_data'; import 'dart:mirror'; RawDatagramSocket.bind(InternetAddress.ANY_IP_V4, 20777).then((RawDatagramSocket socket){ socket.listen((RawSocketEvent e){ Datagram d = socket.receive(); if (d == null) return; ByteBuffer buffer = d.data.buffer; DKByteData data = new DKByteData(buffer); exit

Open Contacts on device via icon tap flutter

笑着哭i 提交于 2021-01-28 21:47:05
问题 Is it possible to open the contacts on a device from an icon tap in flutter? I am able to open the phone function using url_launcher's plugin.I have used the contacts plugin but we dont have a need to manage contacts from our application, we want to use the phones functionality for managing contacts. 回答1: You can achieve this using Flutter platform channels and android Intent.ACTION_VIEW intent. For example in your MainActivity register new channel and launch Contacts activity: MethodChannel

Preload Image Without BuildContext

杀马特。学长 韩版系。学妹 提交于 2021-01-28 21:33:53
问题 Is there a way to load images in Flutter in a function without access to a BuildContext? Flutter can preload images with precacheImage() which requires a BuildContext and is inconvenient to use. I would like to load images in the initState() method of a StatefulWidget which precacheImage() does not support. There is an open issue about preloading images that suggests loading images without a BuildContext is not currently supported. https://github.com/flutter/flutter/issues/26127 回答1: I know

Flutter, using a bloc in a bloc

家住魔仙堡 提交于 2021-01-28 21:22:22
问题 I have two BLoCs. EstateBloc EstateTryBloc My Application basically gets estates from an API and displays them in a similar fashion Now I wanted to add a sort functionality, but I could only access the List of Estates via a specific state. if(currentState is PostLoadedState){{ print(currentState.estates); } I wanted to make the List of estates available for whichever bloc, that needed that list. What I did was, I created the EstateTryBloc, which basically contains the List of estates as a

Datepicker not setting input in TextFormField

牧云@^-^@ 提交于 2021-01-28 21:15:26
问题 See the issue at https://dartpad.dev/c8fc4e640c882616c372653c92362b17 The Datepicker is opening and setting the date in the state, but the selected date is not visible in the TextFormField. Any solution? 回答1: You can copy paste run full code below You can in onTap await _selectDate(context); and set date string with TextEditingController() code snippet TextEditingController _textEditingController = TextEditingController(); Widget buildDateField() { return TextFormField( controller:

How to merge stream using StreamZip in Dart

此生再无相见时 提交于 2021-01-28 19:52:42
问题 I have two streams: Stream<List<Order>> stream1 = pendingStream(); Stream<List<Order>> stream2 = preparingStream(); I'm trying to use StreamZip from the package:async/async.dart package to merge the streams like so... Stream<List<Order>> getData() { Stream<List<Order>> stream1 = pendingStream(); Stream<List<Order>> stream2 = preparingStream(); return StreamZip([stream1, stream2]); } However it won't compile. Saying: The element type 'Stream<List<Order>>' can't be assigned to the list type