How to debounce action in Flutter

Issue #293 Answer This is useful to throttle TextField change event. You can make Debouncer class using Timer import 'package:flutter/foundation.dart'; import 'dart:async'; class Debouncer { final int milliseconds; VoidCallback action; Timer _timer; Debouncer({ this.milliseconds }); run(VoidCallback action) { if (_timer != null) { _timer.cancel(); } _timer = Timer(Duration(milliseconds: milliseconds), action); } } Declare and trigger final _debouncer = Debouncer(milliseconds: 500); onTextChange(String text) { => print(text)); }

May 30, 2019 路 1 min 路 Khoa Pham

How to resolve deep json object in Dart

Issue #198 If we are not on the edge with GRPC and Protocol Buffer, then most likely we are going to deal with Restful and JSON. In one of my Flutter apps I needed to consume JSON JSON and serialization The guide at is definitely the way to go. Currently there are 2 ways. One is to manually use dart:convert package Map<String, dynamic> user = jsonDecode(jsonString); The other way is to use json_serializable to generate parsing code...

April 8, 2019 路 2 min 路 Khoa Pham

How to fix ApiException 10 in Flutter for Android

Issue #188 Get error 10 with google_sign_in package. Read Certain Google Play services (such as Google Sign-in and App Invites) require you to provide the SHA-1 of your signing certificate so we can create an OAuth2 client and API key for your app Credentials -> OAuth client id If we specify SHA1 in firebase, then will generate an Android oauth for us keytool -list -v -keystore {keystore_name} -alias {alias_name} Use correct keystore for debug and release...

March 24, 2019 路 1 min 路 Khoa Pham

How to get Google account photo in Flutter

Issue #187 If you use Flutter, then you can access it via endpoint, code uses google_sign_in library import 'package:google_sign_in/google_sign_in.dart'; Future<String> getPhotoUrl(GoogleSignInAccount account, String userId) async { // final authentication = await account.authentication; final url = '${userId}?personFields=photos'; final response = await http.get( url, headers: await account.authHeaders ); final data = json.decode(response.body); return data['photos'].first['url']; } You will get something like { resourceName: people/998812322529259873423, etag: %EgQBAzcabcQBAgUH, photos: [{metadata: {primary: true, source: {type: PROFILE, id: 107721622529987673423}}, url: https://lh3....

March 24, 2019 路 1 min 路 Khoa Pham