Google places autocomplete doesn't work properly - flutter

Is daily limit really only 1 request or am I missing something? Sometimes I get suggestions but they disappear, on google console metrics I have 97% of 403 error. I use default following code:
Future<Null> displayPrediction(Prediction p) async {
const kGoogleApiKey = "";
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);
if (p != null) {
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(p.placeId);
var address = await Geocoder.local.findAddressesFromQuery(p.description);
// print(lat);
// print(address);
}
}
Prediction p = await PlacesAutocomplete.show(
context: context, apiKey: kGoogleApiKey);
displayPrediction(p);

Related

If want to use youtube user ID All the same people in flutter Of uploading files, it can be done or not

To upload files to youtube How to do it, I have been studying for about a while.
class YoutubeService {
static Future<YouTubeApi> getYoutubeApi() async {
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: <String>[
YouTubeApi.youtubeReadonlyScope,
YouTubeApi.youtubeUploadScope
],
);
await googleSignIn.signIn();
// final GoogleSignInAccount? googleSignInAccount = await googleSignIn.signIn();
var httpClient = await googleSignIn.authenticatedClient();
if (httpClient == null) {
print("You didn't allow to proceed with YouTube access");
}
return YouTubeApi(httpClient!);
}
static Future<VideoListResponse> listYoutubePlaylists() async {
var youTubeApi = await getYoutubeApi();
var data = await youTubeApi.videos.list(
['snippet'],
chart: "mostPopular",
);
return data;
}
static File? f;
static Future<Video>? videoInsertRequest;
static Future<Video> upload() async {
var youTubeApi = await getYoutubeApi();
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
f = File(result.files.single.path.toString());
}
//File f = File('assets/sample-mp4-file-small.mp4');
Stream<List<int>> stream = f!.openRead();
Media m = Media(stream, (await f!.length()));
Video video = Video(
snippet: VideoSnippet(
title: 'Test Video',
description: 'Test Upload for My App',
categoryId: '22',
),
);
videoInsertRequest = youTubeApi.videos.insert(
video,
['snippet', 'status'],
uploadMedia: m,
);
videoInsertRequest!.whenComplete(
() => print("Succeed")
);
return videoInsertRequest!;
}
}
if function getYoutubeApi().How do I enter the desired code?
Another question of this function is if login app with google, is this function call if not set? the desired ID
I call upload() function but not upload to youtube. which has been waiting for a very long time because there is no print Succeed value. I am going to develop a progress bar after print Succeed succeeds.

Dart the operator [] isn't defined for 'Future<Map<String,Object>> Function(String)'

I'm trying to set up Auth0 for my Flutter app from this demo, but I ran into this issue. I've only been using Flutter for a little while, and I fixed a few errors, but can't fix this one. I checked for other answers here, and tried the documentation too. The error message is;
The operator [] isn't defined for 'Future<Map<String,Object>> Function(String)'
This is the method with the error;
Future<void> loginAction() async {
setState(() {
isBusy = true;
errorMessage = '';
});
try {
final AuthorizationTokenResponse? result =
await appAuth.authorizeAndExchangeCode(
AuthorizationTokenRequest(
AUTH0_CLIENT_ID,
AUTH0_REDIRECT_URI,
issuer: 'https://$AUTH0_DOMAIN',
scopes: ['openid', 'profile', 'offline_access'],
promptValues: ['login']
),
);
Map<String, Object> parseIdToken(String idToken) {
final parts = idToken.split(r'.');
assert(parts.length == 3);
return jsonDecode(
utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))));
}
Future<Map<String, Object>> getUserDetails(String accessToken) async {
final url = 'https://$AUTH0_DOMAIN/userinfo';
final response = await http.get(Uri.parse(
url,
));
if (response.statusCode == 200) {
return jsonDecode(response.body);
} else {
throw Exception('Failed to get user details');
}
}
await secureStorage.write(
key: 'refresh_token', value: result!.refreshToken);
setState(() {
isBusy = false;
isLoggedIn = true;
name = parseIdToken['name'];
picture = getUserDetails['picture'];
});
} catch (e, s) {
print('login error: $e - stack: $s');
setState(() {
isBusy = false;
isLoggedIn = false;
errorMessage = e.toString();
});
}
}
And the lines that are erroring are;
name = parseIdToken['name'];
picture = getUserDetails['picture'];
Can this be fixed?
getUserDetails is a function, and so it doesn't have a [] operator.
Instead, try: var userDetails = await getUserDetails("token..."); picture = userDetails["picture"];

Firebase Dynamic Links in flutter seems to recognize it was opened through a link but the link is always null

I'm using dynamic links ^0.7.0+1
When I press the link it loads the app, but doesn't navigate to the page I wanted, I've printed the link I receive, and it's always null, both when the app is in the background or not running at all.
Future<void> retrieveDynamicLink(BuildContext context) async {
List<String> linkData;
print('in retrieve link');
final PendingDynamicLinkData data =
await FirebaseDynamicLinks.instance.getInitialLink();
_handleDynamicLink(data);
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
linkData = await _handleDynamicLink(dynamicLink);
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});
if (data != null) {
AppRoutes.pushLinkEntryPage(
context: context, spreadsheetId: linkData[0], grade: linkData[1]);
}
}
static Future<List<String>> _handleDynamicLink(
PendingDynamicLinkData data) async {
String ssId = '';
String grade = '';
final Uri deepLink = data?.link;
print('deepLink = $deepLink');
if (deepLink == null) {
return null;
}
if (deepLink.queryParameters.containsKey('ss')) {
ssId = deepLink.queryParameters['ss'];
print('in retrieve link: ssID = $ssId');
}
if (deepLink.queryParameters.containsKey('gd')) {
grade = deepLink.queryParameters['gd'];
print('in retrieve link: gd = $grade');
}
return [ssId, grade];
}
I wasted couple of hours on this, and found the fix to be using the "Long dynamic link" instead of the "Deep link".
See attached image below:(This show details of the dynamic link in console)

Flutter : Get daily points system button error

I made a function for users to get daily points (every 24 Hours). The function is linked with Firebase Firestore.
My problem is that if I close the app, relaunch it and click the triggering button ($checkPoints). It will add extra points to database even if the user did it less than 24 Hours ago !
Can you please check the code under and help me fix this?
import 'dart:convert';
import 'dart:math';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:http/http.dart' as http;
class Authfirestore {
final String uid;
int points;
var dateFromApitme;
String lastTimeGotPointsFromFirebase;
Authfirestore({this.uid, this.points});
Firestore _firestore = Firestore();
Future checkPoints() async {
await dateApi();
if (dateFromApitme != null ) {
try {
if (lastTimeGotPointsFromFirebase != dateFromApitme && dateFromApitme != null) {
await getData();
dynamic result = _firestore
.collection('users')
.document('Jm7bx8NOE9Nfx6P8S1wD')
.setData({
'points': points + 1,
'LastTimeGotPoints' :dateFromApitme,
});
await getData();
print(result.toString());
trackingData();
} else {
print('You toke your cridit ');
}
} catch (e) {
print('Error in cehckpoints $e');
}
}
}
Future trackingData() async {
await Firestore.instance
.collection('users')
.document('Jm7bx8NOE9Nfx6P8S1wD')
.collection('tracking')
.document(_randomString(20))
.setData({
'date': DateTime.now(),
});
}
Future getData() async {
await Firestore.instance
.collection('users')
.document('Jm7bx8NOE9Nfx6P8S1wD')
.get()
.then((DocumentSnapshot ds) {
points = ds.data['points'];
lastTimeGotPointsFromFirebase = ds.data['LastTimeGotPoints'];
print('number of points is $points');
});
}
String _randomString(int length) {
va
r rand = new Random();
var codeUnits = new List.generate(length, (index) {
return rand.nextInt(33) + 89;
});
return new String.fromCharCodes(codeUnits);
}
Future dateApi() async {
var response =
await http.get('http://worldtimeapi.org/api/timezone/Asia/Muscat');
if (response != null) {
var data0 = jsonDecode(response.body);
var data01 = data0['datetime'];
dateFromApitme = data01.substring(0, 9);
} else {
dateFromApitme = null;
print('Please Check Your internet');
}
}
}

Google Places AutoComplete not Displaying Addresses when Searching

I am currently working on an app that uses google places autocomplete to find addresses around the world. I have implemented it in the following way:
Position currentPosition;
var placeId, address;
double lat, lng;
getCurrentLocation(){
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
geolocator
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
.then((Position position){
setState(() {
currentPosition = position;
});
}).catchError((e){
print(e);
});
}
Future<Null> displayPrediction(Prediction p) async {
if (p != null) {
PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
placeId = p.placeId;
lat = detail.result.geometry.location.lat;
lng = detail.result.geometry.location.lng;
address = await Geocoder.local.findAddressesFromQuery(p.description);
}
}
onPressed: () async {
print(currentPosition.latitude);
print(currentPosition.longitude);
Prediction prediction = await PlacesAutocomplete.show(
context: context,
apiKey: googleApiKey,
location: Location(currentPosition.latitude, currentPosition.longitude),
radius: 100000000,
mode: Mode.overlay,
language: "en",
);
However, whenever I type something into the search bar, I do not receive any autocompleted results and I am not sure why (image attached). If it makes any difference, I am using the iOS simulator. I haven't yet tested on Android. Any help would be much appreciated.