skip to Main Content

Question might be misleading, but I’m currently working on a project where I use Get.toNamed a lot and I’m sending some data every time. But, when I hot reload the changes I get

════════ Exception caught by widgets library ═══════════════════════════════════
type 'Null' is not a subtype of type `int` 

and I’m changing route with

onTap: () {
    print(_sliderValue);
    Get.toNamed('/stations/detail/booking', arguments: {
        'duration': _sliderValue,
    });
},

Is there any proper way of not losing data while routing between pages or hot reload?

2

Answers


  1. This may be because the variable is private with the underscore.

    Try sliderValue instead of _sliderValue

    Login or Signup to reply.
  2. Im always using Get.toNamed to send arguments but never found issue like this soo maybe you can try this

    You can route to page by SecondPage.show(somethingId : 'id#0');

    class SecondPage extends StatelessWidget {
      static String get name => '/second-page';
    
      const SecondPage({Key? key}) : super(key: key);
    
      static Future<void> show({
        required String somethingId,
      }) async {
        await Get.toNamed(
          name,
          arguments: {
            'somethingId': somethingId,
          },
        );
      }
    
      @override
      Widget build(BuildContext context) {
       ....
      }
    

    and in controller

    class SecondPageController extends GetxController {
      @override
      void onInit() async {
        somethingId.value = Get.arguments['somethingId'] ?? '';
    
        super.onInit();
      }
    
      final somethingId = ''.obs;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search