jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.43k stars 1.63k forks source link

Unexpected null value #2217

Open muntazir143 opened 2 years ago

muntazir143 commented 2 years ago

I'm building my app for flutter web and using getx as state management. This is the error I'm getting consistently and I can't get any solution looking up the internet.

This is my main page code

// import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:crony_store/config/theme/app_theme.dart';
import 'dart:ui' as ui;
import 'package:crony_store/constants/app_strings.dart';
import 'package:crony_store/controllers/theme_controller.dart';
import 'package:crony_store/views/home/components/app_drawer.dart';
import 'package:crony_store/views/mix_match/mix_match_view.dart';
import 'package:crony_store/views/auth/login/login_view.dart';
import 'package:crony_store/views/get_started/started_view.dart';
import 'package:crony_store/views/home/home_view.dart';
import 'package:crony_store/views/modify_items/modify_item_view.dart';
import 'package:crony_store/views/plu_group/plu_group_view.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:device_preview/device_preview.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'config/routes/app_pages.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  // AwesomeNotifications().initialize(
  //   null,
  //   [
  //     NotificationChannel(
  //       channelKey: "basic_channel",
  //       channelName: "Basic Notifications",
  //       channelDescription: "Basic and high priority immediate notifications.",
  //       importance: NotificationImportance.High,
  //       channelShowBadge: true,
  //     ),
  //     NotificationChannel(
  //       channelKey: "scheduled_channel",
  //       channelName: "Scheduled Notifications",
  //       channelDescription: "Scheduled notification reminders.",
  //       importance: NotificationImportance.High,
  //     ),
  //   ],
  // );
  await GetStorage.init();
  // * Keep this code
  // runApp(
  //   DevicePreview(
  //     enabled: !kReleaseMode,
  //     builder: (context) => const MyApp(),
  //   ),
  // );

  runApp(
    const MyApp(),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(ThemeController());
    var theme = controller.switchTheme();
    return GetMaterialApp(
      useInheritedMediaQuery: true,
      locale: DevicePreview.locale(context),
      builder: DevicePreview.appBuilder,
      debugShowCheckedModeBanner: false,
      title: AppStrings.appName,
      theme: theme,
      getPages: AppPages.pages,
      home: const HomeView(),
    );
  }
}
import 'package:crony_store/controllers/home_view_controller.dart';
import 'package:crony_store/utils/helpers/device_type_helper.dart';
import 'package:crony_store/views/card_reconciliation/card_reconciliation_view.dart';
import 'package:crony_store/views/daily_entry/daily_entry_view.dart';
import 'package:crony_store/views/daily_task/daily_task_view.dart';
import 'package:crony_store/views/departments/departments_view.dart';
import 'package:crony_store/views/edit_mix_match/edit_mix_match_view.dart';
import 'package:crony_store/views/home/components/app_drawer.dart';
import 'package:crony_store/views/home/components/grid_view.dart';
import 'package:crony_store/views/home/components/my_app_bar.dart';
import 'package:crony_store/views/home/components/my_flexible_app_bar.dart';
import 'package:crony_store/views/item_listing/item_listing_view.dart';

import 'package:crony_store/views/mix_match/mix_match_view.dart';
import 'package:crony_store/views/modify_items/modify_item_view.dart';
import 'package:crony_store/views/money_services/money_services_view.dart';
import 'package:crony_store/views/payroll_check/payroll_check_view.dart';
import 'package:crony_store/views/petty_cash/petty_cash_view.dart';
import 'package:crony_store/views/physical_entry/physical_entry_view.dart';
import 'package:crony_store/views/plu_group/plu_group_view.dart';
import 'package:crony_store/views/reports/reports_view.dart';
import 'package:crony_store/views/support_tickets/support_tickets_view.dart';
import 'package:crony_store/views/vendor_check/vendor_check_view.dart';
import 'package:crony_store/widgets/common_dialog.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../item_search/item_search_view.dart';

class HomeView extends StatelessWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(HomeViewController());
    var deviceType = getDeviceType();
    final width = MediaQuery.of(context).size.width;
    double expandedHeight = 300;
    double collapsedHeight = 90;
    ScrollController scrollController =
        ScrollController(initialScrollOffset: expandedHeight - 140);
    return Scaffold(
      key: controller.scaffoldKey,
      drawer: const AppDrawer(),
      body: GestureDetector(
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
          // print(deviceType);
          // print(width);
          // if (deviceType == DeviceType.phone) {
          //   print("yes");
          // }
        },
        child: CustomScrollView(
          controller: scrollController,
          slivers: [
            SliverAppBar(
              pinned: true,
              expandedHeight:
                  controller.role == 'admin' ? expandedHeight : collapsedHeight,
              floating: true,
              collapsedHeight: collapsedHeight,
              centerTitle: true,
              elevation: 0.0,
              automaticallyImplyLeading: false,
              title: const MyAppBar(),
              backgroundColor: Theme.of(context).primaryColor,
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                  bottomRight: Radius.circular(100),
                  bottomLeft: Radius.circular(100),
                ),
              ),
              flexibleSpace: FlexibleSpaceBar(
                background: controller.role == 'admin'
                    ? const MyFlexibleAppBar()
                    : const SizedBox(),
              ),
              bottom: PreferredSize(
                preferredSize: Size(Get.width, 50),
                child: Stack(
                  clipBehavior: Clip.none,
                  children: [
                    Positioned(
                      child: SizedBox(
                        width: Get.width / 1.3,
                        child: Material(
                          elevation: 10.0,
                          color: Theme.of(context).cardColor,
                          borderRadius: BorderRadius.circular(50.0),
                          child: TextField(
                            decoration: InputDecoration(
                              // fillColor: Colors.white,
                              filled: true,
                              suffixIcon: const Icon(
                                Icons.mic_rounded,
                                color: Colors.grey,
                              ),
                              hintText: "Search Here...",
                              contentPadding:
                                  const EdgeInsets.fromLTRB(10, 0, 10, 0),
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(50.0),
                                borderSide: BorderSide.none,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),

            SliverPadding(
              padding: const EdgeInsets.all(16.0),
              sliver: SliverGrid.count(
                crossAxisCount: 3,
                mainAxisSpacing: 25.0,
                crossAxisSpacing: 25.0,
                children: [

                  CustomGridView(
                    image: 'assets/svg_icons/item_search.svg',
                    text: 'Item Search',
                    onTap: () {
                      Get.to(() => const ItemSearchView());
                    },
                  ),

                ],
              ),
            ),

            SliverToBoxAdapter(
              child: Container(
                height: 700,
              ),
            )
          ],
        ),
      ),
    );
  }
}

This is the error I'm getting:

The following TypeErrorImpl was thrown building Directionality(textDirection: ltr):
Unexpected null value.

The relevant error-causing widget was
Directionality
..\…\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_

Screenshots image

Flutter Version: Flutter 2.10.0

Getx Version: get: ^4.6.1

Describe on which device you found the bug: Chrome

jonataslaw commented 2 years ago

Try comment this line: builder: DevicePreview.appBuilder,

Shreemanarjun commented 2 years ago

@jonataslaw yaa it throwing bug if we are using device preview.

muntazir143 commented 2 years ago

@jonataslaw The issue still persists even after removing the device preview dependency. Unexpected null value. If I hot reload with having that error then it also throws this.

image

muntazir143 commented 2 years ago

@jonataslaw Have you found any solution? I'm in the middle of a project. Please look into it.

Shreemanarjun commented 2 years ago

1661 Please check this issue. This may fix your problem.