Exception caught by widgets library,widgets/framework.dart:Failed assertion: line 5191 pos 16: owner!._debugCurrentBuildTarget == this: is not true

27 views Asked by At

Exception caught by widgets library===package:flutter/src/widgets/framework.dart': Failed assertion: line 5191 pos 16: 'owner!._debugCurrentBuildTarget == this': is not true.

When I click Submit Button in the provided code I'm getting the above error, the error occured when I tried to create a Navigation bar for my Flutter App

//Code Implementation of UserLogin


import 'package:flutter/material.dart';
import 'package:green_pulse/pages/dashboard.dart';
import 'package:green_pulse/pages/userregistration.dart';

class UserLogin extends StatelessWidget {
         UserLogin({super.key});
        
          @override
          Widget build(BuildContext context) {
            return  Scaffold(
              backgroundColor: Colors.white,
              body:SafeArea(
                child:Column(
                  children: [
                       SizedBox(height: 50,),
                        Center(
                            child: Text('Hey there!',
                              style: TextStyle(color: Colors.black,
                               fontSize: 15
                              ),
                            
                            ),
                          ),

                          SizedBox(height: 5,),

                        //Welcome Back
                          Center(
                            child: Text('Welcome Back!',
                              style: TextStyle(color: Colors.black,
                               fontSize: 25,
                               fontWeight: FontWeight.bold
                              ),
                            
                            ),
                          ),

                        SizedBox(height: 40,),

                        //Username and password
                        Center(
                          child: Padding(
                              padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
                               child:TextField(
                               decoration: InputDecoration(
                               border: OutlineInputBorder(),
                               hintText: 'Username',
                               ),
                              ),
                             ),
                        ),

                          // SizedBox(height: 4,),

                          Center(
                                child: Padding(
                                  padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
                                  child: TextField(
                                    decoration: InputDecoration(
                                      border: OutlineInputBorder(),
                                      hintText: 'Password',
                                                                  ),
                                    obscureText: true, // Set obscureText to true
                                  ),
                                ),
                              ),

                         SizedBox(height: 4,),     

                        //forget password      
                          Center(
                            child: Text('Forget Password',
                              style: TextStyle(color: Colors.black,
                               fontSize: 15,
                              ),
                            
                            ),
                         //   onTap: () => launchUrlString('https://www.google.com'), 
                          ),

                           SizedBox(height: 40,),

                        //Login button
                           Center(
                              child: MaterialButton(
            onPressed: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (ctx)=>Dashboard()));
            }, // Replace with your desired action
            color:Color.fromARGB(255, 134, 157, 240),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(60.0),
            ),
            padding: EdgeInsets.symmetric(
              horizontal: 80.0,
              vertical: 20.0,
            ),
            child:  Text(
              'Login',
              style: TextStyle(
                fontSize: 20.0,
                color: Colors.white,
              ),
            ),
          ),

                           ),



                        //Login with google
                        SizedBox(height: 150,),

                        Center(
                          child: Text('Or',
                           style: TextStyle(
                            fontSize: 15, 
                           ),
                          ),
                        ),

                        SizedBox(height: 10,),

                      Material(
                              child: InkWell(
                              onTap: () {
                             //   Navigator.of(context).push(MaterialPageRoute(builder: (ctx)=>UserRegister())); to be updated later...
                              },
                              child: ClipRRect(
                              borderRadius: BorderRadius.circular(20.0),
                              child: Image.asset('lib/images/—Pngtree—google internet icon vector_12256707.png',
                               height: 60.0),
                                ),
                               ),
                              ),


                        //New user
                         SizedBox(height: 30,),
                         Material(
                          child: InkWell(
                            onTap:(){
                              Navigator.of(context).push(MaterialPageRoute(builder: (ctx)=>UserRegister()));
                            },
                            child: Text('New one, Click to Create an Account :)',
                              style: TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(255, 134, 157, 240),
                              )
                            )
                          )
                          ,)


                  ],
                ) )
            );
            
          }


}


//Code Implementation of Navigation bar

import 'package:flutter/material.dart';
import 'package:green_pulse/pages/dashboard.dart';
import 'package:get/get.dart';
import 'package:iconsax/iconsax.dart';

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

          @override
          Widget build (BuildContext context){
            final controller = Get.put(Navigationcontroller());

            return Scaffold(
               bottomNavigationBar: Obx(
                 () => NavigationBar(
                 height: 80,
                 elevation:0,
                 selectedIndex: controller.selectedIndex.value,
                 onDestinationSelected: (index) =>controller.selectedIndex.value = index,
                  destinations: const [
                      NavigationDestination(icon: Icon(Iconsax.home),label:'Home'),
                      NavigationDestination(icon: Icon(Iconsax.note1), label:'Analytics'),
                      NavigationDestination(icon: Icon(Iconsax.profile1), label: 'Profile')
                  ]),
               ),
                body:Obx(()=> controller.screen[controller.selectedIndex.value]),
            );
          }
}

class Navigationcontroller extends GetxController{
            final Rx<int> selectedIndex = 0.obs;
            final screen =[const Dashboard(),Container(color:Colors.purple),Container(color:Colors.orange),Container(color:Colors.amber)];
}

I'm a beginner in Flutter, I made this with the help of some youtube videos.

I would appreciate any insights or suggestions on what might be causing this error and how to resolve it.

I expect that when I click the submit button, the app should navigate to the Dashboard page without any errors.

Actual image of error while I try to click on the login Button

0

There are 0 answers