createPostInFireStore({String medaiURl, String location, String description}) async{
await postsRef.doc(widget.currentUser.id).collection("userposts").doc(_postId).set(
{"postId": _postId,
"ownerId": widget.currentUser.id,
"userName": widget.currentUser.username,
"mediaurl": medaiURl,
"description": description,
"location": location,
"timeStamp": dateTimeStamp,
},
//SetOptions(merge : true),
);
}
Error Message:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'id' was called on null.
E/flutter (23730): Receiver: null
E/flutter (23730): Tried calling: id
E/flutter (23730): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (23730): #1 _UploadState.createPostInFireStore (package:chat_ui/Components/social_app_homepage.dart:397:43)
E/flutter (23730): #2 _UploadState.handleSumitPost (package:chat_ui/Components/social_app_homepage.dart:420:3)
E/flutter (23730): <asynchronous suspension>
E/flutter (23730): #3 _UploadState.buildLoadingScreen.<anonymous closure> (package:chat_ui/Components/social_app_homepage.dart:443:51)
E/flutter (23730): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter (23730): #5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter (23730): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter (23730): #7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter (23730): #8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter (23730): #9 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:222:7)
E/flutter (23730): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:476:9)
E/flutter (23730): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:77:12)
E/flutter (23730): #12 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (23730): #13 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (23730): #14 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (23730): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (23730): #16 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:358:19)
E/flutter (23730): #17 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter (23730): #18 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter (23730): #19 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (23730): #20 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter (23730): #21 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter (23730): #22 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (23730): #23 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (23730): #24 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (23730): #25 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter (23730): #26 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
E/flutter (23730):
make sure that widget.currentUser has value before calling the createPostInFireStore medthod
I am looking for a method that utilizes the traffic count and based on that gives a rating for that particular location ratings should lie between 0 to 10. I can simply just give rankings 1 to 30 where rank 1 given to the location where most of the traffic occurs. I might need something which scales it between 0 to 10. Any suggestions?
> dput(Data)
structure(list(Traffic.Views = c(3175760L, 2949940L, 2685756L,
2535156L, 2437236L, 2210328L, 2085276L, 1974840L, 1961424L, 1923308L,
1844408L, 1781592L, 1761252L, 1675820L, 1582748L, 1475928L, 1399336L,
1311940L, 1309980L, 1305544L, 1160140L, 1144348L, 1137584L, 1106904L,
946304L, 931992L, 891176L, 815812L, 789788L, 662652L), Names = c("df01",
"df02", "df03", "df04", "df05", "df06", "df07", "df08", "df09",
"df10", "df11", "df12", "df13", "df14", "df15", "df16", "df17",
"df18", "df19", "df20", "df21", "df22", "df23", "df24", "df25",
"df26", "df27", "df28", "df29", "df30")), row.names = c(NA, -30L
), class = "data.frame")
You can use :
rating_0_10 <- function(x) (x-min(x))/(max(x)-min(x)) * 10
Data$scaled <- rating_0_10(Data$Traffic.Views)
Data
# Traffic.Views Names scaled
#1 3175760 df01 10.0000000
#2 2949940 df02 9.1014314
#3 2685756 df03 8.0502072
#4 2535156 df04 7.4509492
#5 2437236 df05 7.0613121
#6 2210328 df06 6.1584142
#7 2085276 df07 5.6608152
#8 1974840 df08 5.2213753
#9 1961424 df09 5.1679912
#10 1923308 df10 5.0163224
#11 1844408 df11 4.7023685
#12 1781592 df12 4.4524151
#13 1761252 df13 4.3714795
#14 1675820 df14 4.0315339
#15 1582748 df15 3.6611877
#16 1475928 df16 3.2361363
#17 1399336 df17 2.9313663
#18 1311940 df18 2.5836056
#19 1309980 df19 2.5758065
#20 1305544 df20 2.5581551
#21 1160140 df21 1.9795727
#22 1144348 df22 1.9167342
#23 1137584 df23 1.8898193
#24 1106904 df24 1.7677394
#25 946304 df25 1.1286901
#26 931992 df26 1.0717406
#27 891176 df27 0.9093282
#28 815812 df28 0.6094446
#29 789788 df29 0.5058915
#30 662652 df30 0.0000000
When I try to sign in with google, the error arises:
W/Firestore( 9373): (22.0.1) [WriteStream]: (c17fcd5) Stream closed with status: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}.
W/Firestore( 9373): (22.0.1) [Firestore]: Write failed at users/hc4f1aKFCFhr7mUgBlWfOyGgIIk1: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter ( 9373): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
E/flutter ( 9373): #0 MethodChannelDocumentReference.set (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:43:7) E/flutter ( 9373): <asynchronous suspension> E/flutter ( 9373): #1 DocumentReference.set (package:cloud_firestore/src/document_reference.dart:78:22) E/flutter ( 9373): #2 DatabaseMethods.addUserInfoToDB (package:messenger_clone/services/database.dart:5:71) E/flutter ( 9373): #3 AuthMethods.signInWithGoogle (package:messenger_clone/services/auth.dart:46:25) E/flutter ( 9373):
#4 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 9373): #5 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 9373): #6 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 9373): #7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 9373): #8 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 9373): #9 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 9373): #10
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15) E/flutter ( 9373): #11
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13) E/flutter ( 9373): #12 FirebaseAuth.signInWithCredential (package:firebase_auth/src/firebase_auth.dart) E/flutter ( 9373): #13
_rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 9373): #14 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 9373): #15 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 9373): #16 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 9373): #17 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 9373): #18 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 9373): #19
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15) E/flutter ( 9373): #20
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13) E/flutter ( 9373): #21 MethodChannelFirebaseAuth.signInWithCredential (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart) E/flutter ( 9373): #22 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 9373): #23
_CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 9373): #24 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 9373): #25 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 9373): #26 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 9373): #27 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 9373): #28
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15) E/flutter ( 9373): #29
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13) E/flutter ( 9373): #30 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart) E/flutter ( 9373): #31 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 9373): #32 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 9373): #33 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 9373): #34 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 9373): #35 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 9373): #36 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 9373): #37
_AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15) E/flutter ( 9373): #38
_completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13) E/flutter ( 9373): #39 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart) E/flutter ( 9373): #40 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 9373): #41 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 9373): #42 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 9373): #43 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 9373): #44 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 9373): #45 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 9373): #46 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7) E/flutter ( 9373): #47
_rootRun (dart:async/zone.dart:1190:13) E/flutter ( 9373): #48 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 9373): #49 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter ( 9373): #50 _CustomZone.b
I tried to edit rulles like this but seems it doen't work
allow read: if auth != null;
allow write: if auth != null;
but when I check the firebase authentificated users, the logged in google user is there.
Try changing your Rule as below
allow read: if request.auth != null;
allow write: if request.auth != null;
How can I set the expiry time of CSRF token in cakePHP 3.7 form.
When I opened a login form for a long time and then submit. It throws black-hole request error. How can I overcome this issue?
[Cake\Controller\Exception\AuthSecurityException] The request has been black-holed
Request
_method=POST&_csrfToken=b61efb3fa9955154dbf38619ff06484e4a45ed35ce6019fd808e0b49c417da7720eb556456341a77a74465160787c0d5561263416bac3f585330d165493681e5&email_address=brittany%40rootrez.com&redirect=%2Fadmin%2Fproperty%2F&_Token%5Bfields%5D=406d43c1169b502cadd7e41e2ec0973335d316e1%253Aredirect&_Token%5Bunlocked%5D=g-recaptcha-response
Response
[Cake\Controller\Exception\AuthSecurityException] The request has been black-holed
#0 /var/www/rootrez/vendor/cakephp/cakephp/src/Controller/Component/SecurityComponent.php(124): Cake\Controller\Component\SecurityComponent->_validatePost(Object(Admin\Controller\AuthController))
#1 /var/www/rootrez/vendor/cakephp/cakephp/src/Event/EventManager.php(353): Cake\Controller\Component\SecurityComponent->startup(Object(Cake\Event\Event))
#2 /var/www/rootrez/vendor/cakephp/cakephp/src/Event/EventManager.php(330): Cake\Event\EventManager->_callListener(Array, Object(Cake\Event\Event))
#3 /var/www/rootrez/vendor/cakephp/cakephp/src/Event/EventDispatcherTrait.php(114): Cake\Event\EventManager->dispatch(Object(Cake\Event\Event))
#4 /var/www/rootrez/vendor/cakephp/cakephp/src/Controller/Controller.php(681): Cake\Controller\Controller->dispatchEvent('Controller.star...')
#5 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(115): Cake\Controller\Controller->startupProcess()
#6 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke(Object(Admin\Controller\AuthController))
#7 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/BaseApplication.php(235): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#8 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#9 /var/www/rootrez/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(162): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#10 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#11 /var/www/rootrez/vendor/dereuromark/cakephp-setup/src/Middleware/MaintenanceMiddleware.php(47): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#12 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Setup\Middleware\MaintenanceMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#13 /var/www/rootrez/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#14 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#15 /var/www/rootrez/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(96): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#16 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#17 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#18 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Server.php(98): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 /var/www/rootrez/webroot/index.php(40): Cake\Http\Server->run()
#20 {main}
Request URL: /admin/login
I'm currently trying to retrieve multiple Set-Cookie fields from a GET or POST request using Dio. I have not been able to do so using either HttpClient or flutter's http.
Using Dio throws an exception:
HttpException: More than one value for header set-cookie
and I want to know how to get around that and handle multiple set-cookie headers, and then send them back in a cookie header.
How to deal with multiple Set-Cookie headers and send them back as a cookie header using Dart/Flutter?
Here is the MCVE
Dio dio = new Dio();
dio.get(urlLogin).then((Response resp){
print('-----Login-----');
print(resp.headers.value('set-cookie'));
});
And the StackTrace
HttpException: More than one value for header set-cookie
#0 _HttpHeaders.value (dart:_http/http_headers.dart:48:7)
#1 loginDio.<anonymous closure> (file:///home/fuguet/Prog/Dart/FPlogin/main.dart:55:24)
#2 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#3 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#5 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#6 Future._complete (dart:async/future_impl.dart:476:7)
#7 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#8 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#11 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#12 Future._complete (dart:async/future_impl.dart:476:7)
#13 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#14 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#15 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#16 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#17 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#18 Future._completeWithValue (dart:async/future_impl.dart:486:5)
#19 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:516:7)
#20 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#22 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:391:30)
#23 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#24 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
As there could be more than one header with the same name, you can't use value(). Instead use [] to retrieve the List<String>.
List<String> rawCookies = resp.headers['set-cookie'];