Getx Snackbar showing initialization error.
I'm having following issue while using Getx Snackbar.
In it snackbar is not showing and also Bottomsheet is also not closing even by using Get.back();
Code and Problem Log is as follow:
Debug Log:
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: LateInitializationError: Field '_controller@984359576' has not been initialized.
E/flutter (31630): #0 SnackbarController._controller (package:get/get_navigation/src/snackbar/snackbar_controller.dart)
package:get/…/snackbar/snackbar_controller.dart:1
E/flutter (31630): #1 SnackbarController._removeEntry
package:get/…/snackbar/snackbar_controller.dart:314
E/flutter (31630): #2 SnackbarController.close
package:get/…/snackbar/snackbar_controller.dart:55
E/flutter (31630): #3 _SnackBarQueue._closeCurrentJob
package:get/…/snackbar/snackbar_controller.dart:370
E/flutter (31630): #4 SnackbarController.closeCurrentSnackbar
package:get/…/snackbar/snackbar_controller.dart:340
E/flutter (31630): #5 GetNavigation.closeCurrentSnackbar
package:get/…/src/extension_navigation.dart:1124
E/flutter (31630): #6 GetNavigation.back
package:get/…/src/extension_navigation.dart:822
E/flutter (31630): #7 MyCustomerListCard.openBottomSheet.
Code -
import 'package:get/get.dart'; import 'package:seller_app/infrastructure/customer_service.dart'; import 'package:seller_app/models/customer/add_customer_model.dart'; import 'package:seller_app/models/customer/all_customer_model.dart'; import 'package:seller_app/models/customer/my_customer_model.dart'; import 'package:seller_app/models/customer/remove_customer_model.dart'; import 'package:seller_app/utils/states.dart';
class CustomerController extends GetxController { var myCustomerData = MyCustomerModel().obs; var _fetchMyCustomerStatus = States.INITIAL_STATE.obs;
get mycustomerDataStatus => _fetchMyCustomerStatus.value;
List<CustomerData> get myCustomerList => myCustomerData.value.data!.data!;
fetchMyCustomersData() async { _fetchMyCustomerStatus.value = States.LOADING_STATE; try { var response = await CustomerService.getMyCustomer(); // print('here $response');
if (response == false) {
_fetchMyCustomerStatus.value = States.ERROR_STATE;
Get.snackbar('Error', 'Something went wrong');
} else {
_fetchMyCustomerStatus.value = States.SUCCESS_STATE;
myCustomerData.value = response;
// Get.snackbar('Data Fetched', 'Hurry');
}
} catch (e) {
_fetchMyCustomerStatus.value = States.ERROR_STATE;
Get.snackbar('Dio Error', 'Opps Something went wrong');
}
}
//Add Customer api
addCustomer(AddCustomerModel customer)async{
try {
var response = await CustomerService.addCustomer(customer);
if(response){
// fetchMyCustomersData();
Get.snackbar('Success', 'Customer added successfully');
myCustomerData.refresh();
Get.back();
}else{
// Get.snackbar('Error', 'Something went wrong');
}
} catch (e) {
print(e);
// Get.snackbar('Error', 'Something went DIO');
}
}
updateCustomer(AddCustomerModel customer)async{ try { var response = await CustomerService.addCustomer(customer); if(response){ fetchMyCustomersData(); // Get.snackbar('Success', 'Customer added successfully'); }else{ Get.snackbar('Error', 'Something went wrong'); } } catch (e) { print(e); Get.snackbar('Error', 'Something went DIO'); }
}
removeCustomer(id)async{ try { var response = await CustomerService.removeCustomer(RemoveCustomerModel(clientId: id.toString())); if(response){ fetchMyCustomersData(); // Get.snackbar('Success', 'Customer added successfully'); }else{ Get.snackbar('Error', 'Something went wrong'); } } catch (e) { print(e); Get.snackbar('Error', 'Something went DIO'); } }
@override void onInit() { // TODO: implement onInit fetchMyCustomersData(); super.onInit(); }
@override void dispose() { // TODO: implement dispose super.dispose(); } }
Same issue
can you try to call same function within onReady() ? Can you specify getx version you are using?
can you try to call same function within onReady() ? Can you specify getx version you are using?
My get version is 4.6.1 , Anyways that error automatically resolves in my project.. Idk how but it is working now.. 😅
same issue
same issue Which version of getx?
@Shreemanarjun get 4.6.5 and I changed getx version to 4.6.1 issue fixed.
When run the get.back() method, it gives an error, the following snackbar controller is not initalized, I am not using the snackbar anyway. Sometimes when I come back from the screen, it gives this error, sometimes when closing the dialogs.
Same, getting this error using Get.back(). Using 4.6.5 and downgraded to 4.6.1 and still getting this. This is an old-ish ticket with only a handful people getting it, must be something we're doing wrong on our ends.
getting the same issue, any update ???
same issue, any update
@jonex41 Check it please I was getting the same error I found what was causing it and realized that I am trying to call the Snackbar without GetMaterialApp loaded.
For example:
void main(){
// Let this be our method that runs the snackbar
checkInternetConnection();
runApp(App());
}
///
void checkInternetConnection(){
if(status){
// Show Snackbar
}else{
// Show Snackbar
}
}
/**
* When you use it this way, Snackbar will not work and will crash.
* It will also cause the `Get.back()` method to crash.
*/
class App extends StatelessWidget{
@override
Widget build(BuildContext context){
return GetMaterialApp(...)
}
}
@taylanyildiz i am using the getmaterialApp(), my issues is that i have it working fine when i open my app on tapping on icon, but when i terminate app and open from notification, that when i get the issues, the Get.back dont work, the snackbar is not showing, all of those