I am trying to connect my Flutter app with Firebase but it shows lots of error I don't know what is wrong. In this basically I am pressing the flat button to connect using firbase_auth and create a user.
I am using AndroidX and installed packages and also tried flutter clean, but nothing works, I followed all instructions in firebase to register my app for android and also multiDexEnabled to true in app level build.gradle
My code:-
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
class ConnectionPage extends StatelessWidget {
final _auth = FirebaseAuth.instance;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white12,
title: Text("Connection Page"),
),
backgroundColor: Colors.black,
body: Center(
child: Container(
height: 400,
child: FlatButton(
child: Text("Button"),
onPressed: () async {
final userInfo = await _auth.createUserWithEmailAndPassword(email: "vishnu#email.com", password: "1234");
print(userInfo.user);
}
),
),
),
);
}
}
and this is pubspec.yaml
name: stockexchange
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
google_fonts: ^0.3.10
charts_flutter: ^0.9.0
firebase_core: ^0.4.4+3
firebase_auth: ^0.16.0
cloud_firestore: ^0.13.5
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- images/
fonts:
- family: CustomIcon
fonts:
- asset: fonts/CustomIcon.ttf
and this the error I am having after running and typing
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##19.3.0:218)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.getAuth(FirebaseAuthPlugin.java:129)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.onMethodCall(FirebaseAuthPlugin.java:143)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#plugins.flutter.io/firebase_auth( 6904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/flutter ( 6904): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, FirebaseApp with name [DEFAULT] doesn't exist. , null)
E/flutter ( 6904): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 6904): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter ( 6904): <asynchronous suspension>
E/flutter ( 6904): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48)
E/flutter ( 6904): #3 MethodChannelFirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth_platform_interface/src/method_channel_firebase_auth.dart:64:23)
E/flutter ( 6904): #4 FirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth/src/firebase_auth.dart:64:10)
E/flutter ( 6904): #5 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6)
E/flutter ( 6904): #6 FirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth/src/firebase_auth.dart:57:52)
E/flutter ( 6904): #7 ConnectionPage.build.<anonymous closure> (package:stockexchange/pages/connection_spec_page.dart:42:46)
E/flutter ( 6904): #8 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6)
E/flutter ( 6904): #9 ConnectionPage.build.<anonymous closure> (package:stockexchange/pages/connection_spec_page.dart:38:30)
E/flutter ( 6904): #10 InputBoardState.build.<anonymous closure> (package:stockexchange/components/input_board.dart:110:24)
E/flutter ( 6904): #11 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter ( 6904): #12 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter ( 6904): #13 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 6904): #14 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 6904): #15 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 6904): #16 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter ( 6904): #17 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter ( 6904): #18 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 6904): #19 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter ( 6904): #20 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 6904): #21 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter ( 6904): #22 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter ( 6904): #23 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 6904): #24 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 6904): #25 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 6904): #26 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 6904): #27 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 6904): #28 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 6904): #29 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 6904): #30 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 6904): #31 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 6904): #32 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter ( 6904):
This could happen if you skip some of the necessary steps to hook up your Flutter app to Firebase. You not only have to place google-service.json file into your android/app directory, but you also have to edit two build.gradle files.
I would recommend you make sure to follow each and every step in the official documentation below:
https://firebase.google.com/docs/flutter/setup
Related
I get the following errors while running my app on my emulator:
E/flutter ( 6796): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled
Exception: MissingPluginException(No implementation found for method
Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
E/flutter ( 6796): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter ( 6796): <asynchronous suspension>
E/flutter ( 6796): #1 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:342:35)
E/flutter ( 6796): <asynchronous suspension>
E/flutter ( 6796): #2 MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:22)
E/flutter ( 6796): <asynchronous suspension>
E/flutter ( 6796): #3 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75:7)
E/flutter ( 6796): <asynchronous suspension>
E/flutter ( 6796): #4 Firebase.initializeApp (package:firebase_core/src/firebase.dart:44:9)
E/flutter ( 6796): <asynchronous suspension>
E/flutter ( 6796): #5 main (package:my_app/main.dart:16:3)
E/flutter ( 6796): <asynchronous suspension>
The last mentioned error "main.dart:16:3" is the line with Firebase.initializeApp in the following code:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
...
The following code is not working, too:
class MainActivity extends StatelessWidget {
Future<void> initializeDefault() async {
print("initAPP");
FirebaseApp app = await Firebase.initializeApp();
print('Initialized default app $app');
}
How can I solve this issue?
Hello im a beginning flutter dev and i want to make a list with data from my cloud firestore database. I dont have any clue how should i do it. any help or advices about my code would be muchly appreciated
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:dinghy1/components/default_button.dart';
import 'package:dinghy1/services/reservations.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../../../constants.dart';
import '../../../size_config.dart';
class Body extends StatefulWidget {
#override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
static List<Map<String, dynamic>> reservations;
static Map<String, dynamic> documents;
static List<QueryDocumentSnapshot> documents2;
static int index;
bool visibility = false;
String rental = ReservationService.rental;
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: SafeArea(
child: Column(
children: [
SizedBox(
height: getPropotionateScreenWidth(20),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: getPropotionateScreenWidth(20)),
child: Container(
decoration: BoxDecoration(
color: kPrimaryColor.withOpacity(0.4),
borderRadius: BorderRadius.circular(30)),
height: getPropotionateScreenHeight(75),
width: double.infinity,
child: Center(
child: Text(
"Sprawdź rezerwacje",
style: TextStyle(
fontSize: getPropotionateScreenWidth(20),
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
),
SizedBox(
height: getPropotionateScreenWidth(20),
),
DatePicker(),
SizedBox(
height: getPropotionateScreenWidth(20),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: getPropotionateScreenWidth(20)),
child: DefaultButton(
text: "Sprawdź",
press: () {
final FirebaseAuth auth = FirebaseAuth.instance;
final User user = auth.currentUser;
String uid = user.uid;
FirebaseFirestore.instance
.collection("users")
.doc(uid)
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
rental = documentSnapshot['rental'].toString();
ReservationService()
.getReservations(
rental,
_DatePickerState.selectedDate
.toString()
.split(" ")[0])
.then((QuerySnapshot docs) {
if (docs.docs.isNotEmpty) {
int i = 0;
index = docs.size - 1;
print(index);
while (i <= index) {
documents = docs.docs[i].data();
if (documents != null) {
reservations.insert(i, documents);
i++;
print(documents);
}
}
}
});
}
});
setState(() {
RentCard.name = documents['name'];
visibility = true;
});
},
),
),
SizedBox(
height: getPropotionateScreenWidth(20),
),
visibility == true
? new Padding(
padding: EdgeInsets.symmetric(
horizontal: getPropotionateScreenWidth(20)),
child: Column(
children: [
// ...List.generate(
// documents2.length,
// (index) => RentCard(reservations: reservations[0]),
// ),
],
),
)
: new Text(
'Wybierz date i naciśnij przycisk aby sprawdzić rezerwacje!')
],
),
),
);
}
}
Here's the code sample that is making an error
E/flutter ( 5082): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'insert' was called on null.
E/flutter ( 5082): Receiver: null
E/flutter ( 5082): Tried calling: insert(0, _LinkedHashMap len:7)
E/flutter ( 5082): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 5082): #1 _BodyState.build.<anonymous closure>.<anonymous closure>.<anonymous closure>
package:dinghy1/…/components/body.dart:89
E/flutter ( 5082): #2 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5082): #3 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5082): #4 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter ( 5082): #5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter ( 5082): #6 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter ( 5082): #7 Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter ( 5082): #8 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter ( 5082): #9 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter ( 5082): #10 Query.get (package:cloud_firestore/src/query.dart)
package:cloud_firestore/src/query.dart:1
E/flutter ( 5082): <asynchronous suspension>
E/flutter ( 5082): #11 ReservationService.getReservations
package:dinghy1/services/reservations.dart:19
E/flutter ( 5082): #12 _BodyState.build.<anonymous closure>.<anonymous closure>
package:dinghy1/…/components/body.dart:76
E/flutter ( 5082): #13 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5082): #14 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5082): #15 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter ( 5082): #16 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter ( 5082): #17 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter ( 5082): #18 Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter ( 5082): #19 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
E/flutter ( 5082): #20 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
E/flutter ( 5082): #21 DocumentReference.get (package:cloud_firestore/src/document_reference.dart)
package:cloud_firestore/src/document_reference.dart:1
E/flutter ( 5082): <asynchronous suspension>
E/flutter ( 5082): #22 _BodyState.build.<anonymous closure>
package:dinghy1/…/components/body.dart:71
E/flutter ( 5082): #23 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:993
E/flutter ( 5082): #24 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:1111
E/flutter ( 5082): #25 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:183
E/flutter ( 5082): #26 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:598
E/flutter ( 5082): #27 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:287
E/flutter ( 5082): #28 BaseTapGestureRecognizer.handlePrimaryPointer
package:flutter/…/gestures/tap.dart:222
E/flutter ( 5082): #29 PrimaryPointerGestureRecognizer.handleEvent
package:flutter/…/gestures/recognizer.dart:476
E/flutter ( 5082): #34 PointerRouter.route
package:flutter/…/gestures/pointer_router.dart:106
E/flutter ( 5082): #35 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:358
E/flutter ( 5082): #36 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:338
E/flutter ( 5082): #37 RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:267
E/flutter ( 5082): #38 GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:295
E/flutter ( 5082): #39 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:240
E/flutter ( 5082): #40 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:213
E/flutter ( 5082): #41 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5082): #42 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5082): #43 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5082): #44 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter ( 5082): #45 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
E/flutter ( 5082):
Here's an error message.
If someone could help me fix that, i would went insane from happiness
In dart, we define lists and maps like this:
static List<Map<String, dynamic>> reservations = [];
static Map<String, dynamic> documents = {};
List<QueryDocumentSnapshot> documents2 = [];
If you want to learn more, read this topic about lists in dart.
Maps are mostly the same.
I have a problem with showing dialog.
When i'm sending push notofication to the device i have error. But the audio play, -->
assetsAudioPlayer.open(
Audio('sounds/alert.mp3'),
);
assetsAudioPlayer.play();
and first dialog --->
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => ProgressDialog(status: 'received trip..',),
);
i also can see.
void fetchRideInfo(String rideID, context){
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => ProgressDialog(status: '..',),
);
DatabaseReference rideRef = FirebaseDatabase.instance.reference().child('rideRequest/$rideID');
rideRef.once().then((DataSnapshot snapshot) {
Navigator.pop(context);
if(snapshot.value != null){
assetsAudioPlayer.open(
Audio('sounds/alert.mp3'),
);
assetsAudioPlayer.play();
double pickupLat = double.parse(snapshot.value["location"]["latitude"].toString()); //**error HERE**
double pickupLng = double.parse((snapshot.value["location"]["longitude"].toString()));
String pickupAddress = snapshot.value['pickup_address'].toString();
double destinationLat = double.parse(snapshot.value['destination']['latitude'].toString());
double destinationLng = double.parse(snapshot.value['destination']['longitude'].toString());
String destinationAddress = snapshot.value['destination_address'];
String paymentMethod = snapshot.value['payment_method'];
TripDetails tripDetails = TripDetails();
tripDetails.rideID = rideID;
tripDetails.pickupAddress = pickupAddress;
tripDetails.destinationAddress = destinationAddress;
tripDetails.pickup = LatLng(pickupLat , pickupLng);
tripDetails.destination = LatLng(destinationLat, destinationLng);
tripDetails.paymentMethod = paymentMethod;
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => NotificationDialog(tripDetails: tripDetails,),
);
}
});
}
THIS MY CONSOLE
E/FlutterFcmService(11685): Fatal: failed to find callback
I/flutter (11685): ride_id: -MPRCo9pHbzEi1pOJOAs
E/flutter (11685): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter (11685): Receiver: null
E/flutter (11685): Tried calling: []("latitude")
E/flutter (11685): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (11685): #1 PushNotificationService.fetchRideInfo.<anonymous closure> (package:cab_driver/helpers/pushnotificationservice.dart:82:68)
E/flutter (11685): #2 _rootRunUnary (dart:async/zone.dart:1194:47)
E/flutter (11685): #3 _CustomZone.runUnary (dart:async/zone.dart:1097:19)
E/flutter (11685): #4 _FutureListener.handleValue (dart:async/future_impl.dart:150:18)
E/flutter (11685): #5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:703:45)
E/flutter (11685): #6 Future._propagateToListeners (dart:async/future_impl.dart:732:32)
E/flutter (11685): #7 Future._completeWithValue (dart:async/future_impl.dart:536:5)
E/flutter (11685): #8 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:254:13)
E/flutter (11685): #9 Query.once (package:firebase_database/src/query.dart)
E/flutter (11685): <asynchronous suspension>
E/flutter (11685):
I dont find any information about this. Many solution about NoSuchMethodError, but HOW implement to my PROBLEM? I dont know. Please help.
first of all, i got an error look like this
I/flutter ( 3245): BLOC Start
I/flutter ( 3245): BLOC Start
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building BlocBuilder<StationBloc, StationState>(dirty, state: _BlocBuilderBaseState<StationBloc, StationState>#24ede):
The getter 'length' was called on null.
Receiver: null
Tried calling: length
The relevant error-causing widget was:
BlocBuilder<StationBloc, StationState> file:///C:/Users/junia/FlutterApp/airportstation/airport_station/lib/view/home_screen.dart:42:18
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _HomeScreenState.buildStationList (package:airport_station/view/home_screen.dart:79:30)
#2 _HomeScreenState.build.<anonymous closure> (package:airport_station/view/home_screen.dart:51:24)
#3 BlocBuilder.build (package:flutter_bloc/src/bloc_builder.dart:90:57)
#4 _BlocBuilderBaseState.build (package:flutter_bloc/src/bloc_builder.dart:162:48)
Then, i went to stackoverflow and found a litte solution
Widget buildStationList(List<AllFlight> allFlight) {
return ListView.builder(
itemCount: allFlight.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
child: ListTile(
title: Text(allFlight[index].airportName + ' - ' + allFlight[index].countryName),
subtitle: Text(allFlight[index].label),
),
),
);
}
);
the problem is on itemCount: allFlight.length, and i change it into itemCount: allFlight?.length ?? 0,
after i run it again. there's still an error
I/flutter ( 3245): BLOC Start
I/flutter ( 3245): BLOC Start
E/flutter ( 3245): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: UnimplementedError
E/flutter ( 3245): #0 StationLoadedState.props (package:airport_station/bloc/station_state.dart:23:29)
E/flutter ( 3245): #1 Equatable.== (package:equatable/src/equatable.dart:50:18)
E/flutter ( 3245): #2 Bloc._bindEventsToStates.<anonymous closure> (package:bloc/src/bloc.dart:261:32)
E/flutter ( 3245): #3 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 3245): #4 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 3245): #5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 3245): #6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 3245): #7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 3245): #8 _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:385:25)
E/flutter ( 3245): #9 _BroadcastStreamController._add (dart:async/broadcast_stream_controller.dart:293:5)
E/flutter ( 3245): #10 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 3245): #11 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 3245): #12 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 3245): #13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 3245): #14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 3245): #15 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:127:11)
E/flutter ( 3245): #16 _MapStream._handleData (dart:async/stream_pipe.dart:224:10)
E/flutter ( 3245): #17 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:157:13)
E/flutter ( 3245): #18 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 3245): #19 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 3245): #20 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 3245): #21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 3245): #22 _DelayedData.perform (dart:async/stream_impl.dart:611:14)
E/flutter ( 3245): #23 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
E/flutter ( 3245): #24 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
E/flutter ( 3245): #25 _rootRun (dart:async/zone.dart:1182:47)
E/flutter ( 3245): #26 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 3245): #27 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 3245): #28 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 3245): #29 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 3245): #30 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 3245): #31 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 3245): #32 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 3245): #33 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 3245): #34 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter ( 3245):
my bloc_state.dart look like this
...
class StationLoadedState extends StationState {
final List<AllFlight> allFlight;
StationLoadedState({ #required this.allFlight });
#override
List<Object> get props => throw UnimplementedError();
}
...
and BlocBuilder
class _HomeScreenState extends State<HomeScreen> {
StationBloc stationBloc;
#override
void initState() {
super.initState();
stationBloc = BlocProvider.of(context);
stationBloc.add(FetchStationEvent());
}
...
body: Container(
child: BlocListener<StationBloc, StationState>(
listener: (context, state) {
if (state is StationErrorState) {
print(state.message);
}
},
child: BlocBuilder<StationBloc, StationState>(
builder: (context, state) {
print('BLOC Start');
if (state is StationInitialState) {
return buildLoading();
} else if (state is StationLoadingState) {
return buildLoading();
} else if (state is StationLoadedState) {
return buildStationList(state.allFlight);
} else if (state is StationErrorState) {
return buildError(state.message);
}
},
),
),
),
...
json response returned successfully when i try print it on http response. did someone know where the problem is?
BlocState has a "props" getter which should return an array of variables to compare states between each other. When you yield same state 2 times in a row, it will compare them using those props and if it's the same state as current - bloc will not yield it again (this is the default way it works when you're using Equatable).
In your code above you have this:
class StationLoadedState extends StationState {
final List<AllFlight> allFlight;
StationLoadedState({ #required this.allFlight });
#override
List<Object> get props => throw UnimplementedError();
}
It throws UnimplementedError when props are called. Change it to an array with your state's params.
class StationLoadedState extends StationState {
final List<AllFlight> allFlight;
StationLoadedState({ #required this.allFlight });
#override
List<Object> get props => [allFlight];
}
note: my both loginpage class and otpscreen class are statefulwidget i just avoid the extra code to show here.
i am trying to authenticate phone number. otp message is coming but not verfying after clicking the submit button here is the error i get
E/flutter (21679): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, null reference, null)
E/flutter (21679): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (21679): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter (21679): <asynchronous suspension>
E/flutter (21679): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48)
E/flutter (21679): #3 MethodChannelFirebaseAuth.signInWithCredential (package:firebase_auth_platform_interface/src/method_channel_firebase_auth.dart:161:23)
E/flutter (21679): #4 FirebaseAuth.signInWithCredential (package:firebase_auth/src/firebase_auth.dart:208:10)
E/flutter (21679): #5 LoginRepository.signIn (package:doorstep/domain/repository/login-repository.dart:36:17)
E/flutter (21679): #6 OtpScreenState.submit.<anonymous closure> (package:doorstep/module/login/otpscreen.dart:90:26)
E/flutter (21679): #7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter (21679): #8 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter (21679): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (21679): #10 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter (21679): #11 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter (21679): #12 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter (21679): #13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter (21679): #14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter (21679): #15 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter (21679): #16 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter (21679): #17 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter (21679): #18 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter (21679): #19 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (21679): #20 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (21679): #21 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (21679): #22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (21679): #23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (21679): #24 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (21679): #25 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (21679): #26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (21679): #27 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (21679): #28 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
This is loginrepository
class LoginRepository{
String verificationId;
var _auth = FirebaseAuth.instance;
Future<void> sendOtp(String _number) async {
final PhoneVerificationCompleted phoneVerificationCompleted =
(AuthCredential credential) {};
final PhoneVerificationFailed phoneVerificationFailed =
(AuthException exception) {
print("Login Faild due to $exception");
};
final PhoneCodeSent phoneCodeSent =
(String verificationId, [int forceResendingToken]) {
this.verificationId = verificationId;
};
final PhoneCodeAutoRetrievalTimeout phoneCodeAutoRetrievalTimeout =
(String verificationId) {
this.verificationId = verificationId;
print("time out");
};
await _auth.verifyPhoneNumber(
phoneNumber: _number,
timeout: Duration(seconds: 120),
verificationCompleted: phoneVerificationCompleted,
verificationFailed: phoneVerificationFailed,
codeSent: phoneCodeSent,
codeAutoRetrievalTimeout: phoneCodeAutoRetrievalTimeout);
}
Future<void> signIn(String otpCode) async {
final AuthCredential authCredential = PhoneAuthProvider.getCredential(
verificationId: verificationId, smsCode: otpCode);
await _auth.signInWithCredential(authCredential);
}
}
this is loginpage class
class LoginPage{
LoginRepository _loginRepository = LoginRepository();
Widget send() {
return FlatButton(
child: Text("Send OTP"),
onPressed: () {
_loginRepository.sendOtp(_numberController.text);
},
);
}
}
this is otp class
class OtpScreen{
LoginRepository _loginRepository = LoginRepository();
Widget submit() {
return FlatButton(
child: Text("Submit"),
onPressed: () async {
_loginRepository.signIn(_otpController.text);
},
);
}
}
This is happening due to the verificationId being null while reaching the manualPhoneAuth function. Somehow verification id is not getting assigned in the codeSent callback function.I changed the verificationId to a static variable and voila, It worked.
Change String verificationId to static String verificationId