codingcafe1 / buddies_gram

This is Flutter Instagram Clone App using Firebase Firestore & Firebase Cloud Functions.
55 stars 35 forks source link

The method 'validate' was called on null. Receiver: null Tried calling: validate() #1

Open abhisondagar605 opened 4 years ago

abhisondagar605 commented 4 years ago

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building CreateAccountPage(dirty, dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#0560e]], state: _CreateAccountPageState#8ae4d): The method 'validate' was called on null. Receiver: null Tried calling: validate()

The relevant error-causing widget was: CreateAccountPage file:///C:/Users/Abhi%20Sondagar/AndroidStudioProjects/instagram_app/lib/pages/HomePage.dart:44:51 When the exception was thrown, this was the stack:

0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)

1 _CreateAccountPageState.submitUserName (package:instagramapp/pages/CreateAccountPage.dart:18:14)

2 _CreateAccountPageState.build (package:instagramapp/pages/CreateAccountPage.dart:88:26)

3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)

4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)

... ════════════════════════════════════════════════════════════════════════════════════════════════════ D/libc-netbsd(27927): [getaddrinfo]: hostname=firestore.googleapis.com; servname=(null); app_uid=10624; ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0 from prox result 0

abhisondagar605 commented 4 years ago

code of createaccountpage class

import 'dart:async';

import 'package:flutter/material.dart'; import 'package:instagramapp/widgets/HeaderWidget.dart';

class CreateAccountPage extends StatefulWidget { @override _CreateAccountPageState createState() => _CreateAccountPageState(); }

class _CreateAccountPageState extends State { final _scaffoldKey = GlobalKey(); final _formKey = GlobalKey(); String userName;

submitUserName() { final form = _formKey.currentState; if (form.validate()) { form.save();

  SnackBar snackBar = SnackBar(content: Text('welcome ' + userName));
  _scaffoldKey.currentState.showSnackBar(snackBar);
  Timer(Duration(seconds: 4), () {
    Navigator.pop(context, userName);
  });
}

}

@override Widget build(BuildContext parentContext) { print('account page'); return Scaffold( key: _scaffoldKey, appBar: header(context, strTitle: 'Settings', disappearedBackButton: true), body: ListView( children: [ Container( child: Column( children: [ Padding( padding: EdgeInsets.only(top: 26.0), child: Text( 'set yp a username', style: TextStyle( fontSize: 26.0, ), ), ), Padding( padding: EdgeInsets.all(17.0), child: Container( child: Form( key: _formKey, autovalidate: true, child: TextFormField( style: TextStyle( color: Colors.white, ), validator: (val) { if (val.trim().length < 5 || val.isEmpty) { return 'user name is very short'; } else if (val.trim().length > 15) { return 'user name is very long'; } else { return null; } }, onSaved: (val) => userName = val, decoration: InputDecoration( enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.white), ), border: OutlineInputBorder(), labelText: 'User name', labelStyle: TextStyle(fontSize: 16.0), hintText: 'must be atleast 5 character', hintStyle: TextStyle(color: Colors.grey), ), ), ), ), ), GestureDetector( onTap: submitUserName(), child: Container( height: 55.0, width: 360.0, decoration: BoxDecoration( color: Colors.green, borderRadius: BorderRadius.circular(8.0), ), child: Center( child: Text( 'Proceed', style: TextStyle( color: Colors.white, fontSize: 16.0, fontWeight: FontWeight.bold, ), ), ), ), ) ], ), ), ], ), ); } }