The getter 'current' was called on null

0

I am creating a signUp form in flutter and I am trying to apply validator on the TextFormField and calling if the user forgets to fill a field he gets validation alert message. But I don't know why it not working. The thing is that I am unable to understand what is the fact here. If anyone knows please help to resolve my issue. I am getting this error :

I/flutter (29245): The getter 'current' was called on null.
I/flutter (29245): Receiver: null
I/flutter (29245): Tried calling: current
I/flutter (29245): The relevant error-causing widget was:
I/flutter (29245):   AnimatedContainer 
lib\signuppage.dart:147
I/flutter (29245): When the exception was thrown, this was the stack:

//*This is my code

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:login_page_flutter/Models/myconstant.dart';
import 'package:login_page_flutter/Models/user.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:login_page_flutter/loginpage.dart';

class SignUpPage extends StatefulWidget {
  @override
  _SignUpPageState createState() => _SignUpPageState();
}

class _SignUpPageState extends State<SignUpPage> {
  var _formKey = GlobalKey<FormState>();
  TextEditingController txtname = TextEditingController();
  TextEditingController txtusername = TextEditingController();
  TextEditingController txtpassword = TextEditingController();
  //TextEditingController txttype = TextEditingController();
  bool isUploading = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Neumorphic(
        child: Form(
          key: _formKey,
          child: Padding(
            padding: EdgeInsets.all(20.0),
            child: ListView(
              children: <Widget>[
                SizedBox(
                  height: 10,
                ),
                Center(
                  child: Container(
                    child: Center(
                      child: Text(
                        'SignUp',
                        style: TextStyle(
                          color: Colors.pink[800],
                          decoration:
                              TextDecoration.combine(List<TextDecoration>()),
                        ),
                      ),
                    ),
                    width: 100,
                    height: 50,
                    decoration: BoxDecoration(
                        color: Colors.grey[300],
                        borderRadius: BorderRadius.all(Radius.circular(78)),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.grey,
                            offset: Offset(4.0, 4.0),
                            blurRadius: 10.0,
                            spreadRadius: 1.0,
                          ),
                          BoxShadow(
                            color: Colors.white,
                            offset: Offset(-4.0, -4.0),
                            blurRadius: 10.0,
                            spreadRadius: 1.0,
                          ),
                        ]),
                  ),
                ),
                SizedBox(
                  height: 20,
                ),
                Card(
                  child: Neumorphic(
                    padding: EdgeInsets.all(30.0),
                    child: Column(
                      children: <Widget>[
                        SizedBox(
                          height: 10,
                        ),
                        Neumorphic(
                          style: NeumorphicStyle(
                            boxShape: NeumorphicBoxShape.roundRect(
                                BorderRadius.circular(10)),
                          ),
                          child: Container(
                            decoration: BoxDecoration(boxShadow: [
                              BoxShadow(
                                color: Colors.white,
                                offset: Offset(4.0, 4.0),
                                blurRadius: 10.0,
                                spreadRadius: 1.0,
                              ),
                              BoxShadow(
                                color: Colors.grey[300],
                                offset: Offset(-4.0, -4.0),
                                blurRadius: 10.0,
                                spreadRadius: 1.0,
                              ),
                            ]),
                            child: TextFormField(
                              validator: (String value) {
                                if (value.isEmpty) {
                                  return 'Please Enter Name';
                                }
                                return null;
                              },
                              decoration: InputDecoration(
                                labelStyle: TextStyle(color: Colors.pink),
                              ),
                              controller: txtname,
                            ),
                          ),
                        ),
                        TextFormField(
                          validator: (String value) {
                            if (value.isEmpty) {
                              return 'Please Enter userName';
                            }
                            return null;
                          },
                          controller: txtusername,
                        ),
                        TextFormField(
                          validator: (String value) {
                            if (value.isEmpty) {
                              return 'Please Enter Password';
                            }
                            return null;
                          },
                          controller: txtpassword,
                        ),
                        SizedBox(
                          height: 10,
                        ),
                      ],
                    ),
                    style: NeumorphicStyle(
                      boxShape: NeumorphicBoxShape.roundRect(
                          BorderRadius.circular(10)),
                    ),
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(50),
                    ),
                  ),
                ),
                SizedBox(height: 30),
                Center(
                  child: AnimatedContainer(
                    decoration: BoxDecoration(
                      boxShadow: [
                        BoxShadow(
                            blurRadius: 15,
                            offset: -Offset(5, 5),
                            color: Colors.white),
                        BoxShadow(
                            blurRadius: 15,
                            offset: Offset(4.5, 4.5),
                            color: Colors.white38),
                      ],
                    ),
                    duration: const Duration(milliseconds: 50),
                    child: getWidgetByStatus(),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Future<void> saveData(dynamic jsonOfuser) async {
    setState(() {
      isUploading = true;
    });
    await Future.delayed(Duration(seconds: MyConstant.VAL_SECONDS), () {});
    return post(
      MyConstant.URL_USER_INSERT,
      body: jsonOfuser,
    ).then((onRecievedResponse) {
      print(onRecievedResponse.body);
      setState(() {
        isUploading = false;
      });
      return null;
    });
  }

  Widget getWidgetByStatus() {
    if (isUploading) {
      return CircularProgressIndicator(
        backgroundColor: Colors.pink,
      );
    } else {
      return NeumorphicButton(
        onPressed: () {
          User user = User(
            id: 11,
            name: txtname.text,
            username: txtusername.text,
            password: txtpassword.text,
            type: 11,
          );
          saveData(
            User.toJson(user),
          );
          if (_formKey.currentState.validate()) {
            setState(
              () {
                SnackBar(
                  backgroundColor: Colors.white60,
                  content: Row(
                    children: <Widget>[
                      Icon(Icons.thumb_up, color: Colors.pink),
                      SizedBox(width: 10),
                      Expanded(
                        child: Text(
                          'Data Inserted Successfully',
                          style: TextStyle(color: Colors.pink),
                        ),
                      )
                    ],
                  ),
                );
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return LoginPage();
                }));
              },
            );
          }
        },
        child: Text(
          'Submit',
          style: TextStyle(color: Colors.pink[800]),
        ),
      );
    }
  }
} 

And This is Console

 I/flutter (29245): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (29245): The following NoSuchMethodError was thrown building Container(bg:
I/flutter (29245):     BoxDecoration(
I/flutter (29245):       boxShadow: [BoxShadow(Color(0xffffffff), Offset(-5.0, -5.0), 15.0,
I/flutter (29245):         0.0), BoxShadow(Color(0x62ffffff), Offset(4.5, 4.5), 15.0, 0.0)]
I/flutter (29245):       )
I/flutter (29245):   ):
I/flutter (29245): The getter 'current' was called on null.
I/flutter (29245): Receiver: null
I/flutter (29245): Tried calling: current
I/flutter (29245): The relevant error-causing widget was:
[38;5;248mI/flutter (29245):   AnimatedContainer[39;49m
I/flutter (29245): When the exception was thrown, this was the stack:
[38;5;244mI/flutter (29245): #0      Object.noSuchMethod  (dart:core-
android
flutter
asked on Stack Overflow Jun 12, 2020 by Ruhma CH • edited Jun 12, 2020 by Ruhma CH

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0