5

I'm using GetX for bottom sheet purpose. i used this below code to implement the functionality. when i press the (i)-info icon i want the bottom sheet to pop-up but instead i'm getting this error.

The following _CastError was thrown while handling a gesture: Null check operator used on a null value

This is the code:

GestureDetector(
    onTap:(){
      Get.bottomSheet(
        Container(
          child: Wrap(
              children:<Widget>[
                ListTile(
                  leading: Icon(Icons.wb_incandescent),
                  title: Text("Testing"),
                  onTap: () => {Get.changeTheme(ThemeData.light())},
                ),
                ListTile(
                  leading: Icon(Icons.wb_incandescent),
                  title: Text("Testing"),
                  onTap: () => {Get.changeTheme(ThemeData.dark())},
                ),
              ]
          ),
        ),
      );
    },
    child: Container(
      width: 30.0,
      height: 30.0,
      decoration: BoxDecoration(
        color: Color(0xFF1D265F),
        borderRadius: BorderRadius.circular(80.0),
      ),

        child: new LayoutBuilder(
          builder: (context, constraint) {
            return new Icon(
              Icons.info_outline_rounded,
              color: widget.cardContent.cardColor,
              size: constraint.biggest.height,
            );
          },
        ),
    ),
  ),
Salim Murshed
  • 1,423
  • 1
  • 8
  • 19
docoj28048
  • 51
  • 1

1 Answers1

-1

Here's your solution.

Source code:

import "package:flutter/material.dart";
import "package:get/get.dart";

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: "Flutter Demo",
      home: const MyHomePage(),
      theme: ThemeData(brightness: Brightness.light),
      darkTheme: ThemeData(brightness: Brightness.dark),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            GestureDetector(
              onTap: () async {
                await Get.bottomSheet(
                  Wrap(
                    children: <Widget>[
                      ListTile(
                        title: const Text("Light"),
                        onTap: () {
                          Get
                            ..changeThemeMode(ThemeMode.light)
                            ..back();
                        },
                        leading: const Icon(Icons.light_mode),
                      ),
                      ListTile(
                        title: const Text("Dark"),
                        onTap: () {
                          Get
                            ..changeThemeMode(ThemeMode.dark)
                            ..back();
                        },
                        leading: const Icon(Icons.dark_mode),
                      ),
                    ],
                  ),
                  backgroundColor: Get.isDarkMode ? Colors.black : Colors.white,
                );
              },
              child: const Center(
                child: Icon(Icons.color_lens),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
Dharam Budh
  • 515
  • 2
  • 9