CodeDon
CodeDon

Reputation: 77

Dart GetX Unexpected Null Value when refreshed

I redirected my Home View page to another view.

class HomeView extends GetView<HomeController> {
  const HomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    return CustomScaffold(
    body: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        
        ElevatedButton(
          onPressed: () {
            Get.to(() => AirView());
          },
          child: Text("GO NEXT"),
        ),
);

After going to the next page, i encounter an error when I REFRESH the page. enter image description here

No Directionality used.

enter image description here

Console Error

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following TypeErrorImpl was thrown building Directionality(textDirection: ltr): Unexpected null value. The relevant error-causing widget was: Directionality Directionality:file:///C:/Flutter/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.5/lib/get_navigation/src/root/get_material_app.dart:328:12 ..\…\root\get_material_app.dart:328 When the exception was thrown, this was the stack: C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63 nullCheck packages/get/get_navigation/src/routes/route_middleware.dart 199:50 page packages/get/get_navigation/src/root/get_material_app.dart 347:23 initialRoutesGenerate packages/flutter/src/widgets/app.dart 1559:27 packages/flutter/src/widgets/navigator.dart 3290:41 restoreState packages/flutter/src/widgets/restoration.dart 887:5 [_doRestore] packages/flutter/src/widgets/restoration.dart 873:7 didChangeDependencies packages/flutter/src/widgets/navigator.dart 3336:11 didChangeDependencies packages/flutter/src/widgets/framework.dart 4963:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4781:5 mount packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget ......

Second Page Codes:

  const AirView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AircoView'),
        centerTitle: true,
      ),
      body: const Center(
        child: Text(
          'AirView is working',
          style: TextStyle(fontSize: 20),
        ),
      ),
    );
  }
}

Upvotes: 2

Views: 1098

Answers (3)

upidev
upidev

Reputation: 21

wrap getbuilder inside getbuilder

see mycode :

GetBuilder<HomeController>(
        init: HomeController(),
        initState: (_) {},
        builder: (_) {
          return GetBuilder<HomeController>(
            builder: (controller) {
              return Scaffold(
                appBar: AppBar(
                  title: const Text('Footware Admin'),
                  centerTitle: true,
                ),
                body: ListView.builder(
                  itemCount: 10,
                  itemBuilder: (context, index) {
                    return ListTile(
                      title: const Text('Title'),
                      subtitle: const Text('Price : 100'),
                      trailing: IconButton(
                          onPressed: () {}, icon: const Icon(Icons.delete)),
                    );
                  },
                ),
                floatingActionButton: FloatingActionButton(
                    onPressed: () {
                      controller.testMethod();
                    },
                    child: Icon(Icons.add)),
              );
            },
          );
        });

Upvotes: 0

CodeDon
CodeDon

Reputation: 77

Managed to solve the issue.

Used get_cli: ^1.8.1 Package

then use this command: get create page:airco on home

This will then automatically generate Children under GetPage in the file app_pages.dart


GetPage(
      name: _Paths.HOME,
      page: () => const HomeView(),
      binding: HomeBinding(),
 children: [
        GetPage(
          name: _Paths.AIRCO,
          page: () => const AircoView(),
        ),
      ],
    )


Paths is from app_routes (automatically created by Get CLI package as well)

Upvotes: 0

MANISH DAYMA
MANISH DAYMA

Reputation: 1240

you are not using materialapp because you are using getmaterialapp than you have to wrap your Directionality in mediaquery like this.

    import 'dart:ui' as ui;
    ...
    new MediaQuery(
        data: new MediaQueryData.fromWindow(ui.window),
        child: new Directionality(
            textDirection: TextDirection.rtl,
            child: new MyHome())))

Upvotes: 0

Related Questions