Created
June 26, 2018 19:16
-
-
Save ThinkDigitalSoftware/04475e93b77312ad679d337350f06652 to your computer and use it in GitHub Desktop.
Boolean Expression must not be null error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:html/dom.dart' as dom; | |
import 'package:html/parser.dart'; | |
import 'package:http/http.dart'; | |
import '../live_kh.dart'; | |
import 'package:flutter/cupertino.dart'; | |
import 'hall_page.dart'; | |
class LoginPage extends StatefulWidget { | |
final String congregationName; | |
final String congregationId; | |
final String congregationUrl; | |
final String imgSrc; | |
final LiveKH liveKH; | |
const LoginPage( | |
{Key key, | |
@required this.congregationName, | |
@required this.congregationId, | |
@required this.imgSrc, | |
@required this.liveKH, | |
@required this.congregationUrl}) | |
: super(key: key); | |
@override | |
_LoginPageState createState() => _LoginPageState(); | |
} | |
class _LoginPageState extends State<LoginPage> { | |
Color loginButtonColor = Colors.grey; | |
TextEditingController _listPassController = TextEditingController(); | |
int dropDownButtonValue = 1; | |
bool _listPassFieldIsValid = false; | |
@override | |
void initState() { | |
debugPrint("Logging into ${widget.congregationName}"); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
double screenWidth = MediaQuery.of(context).size.width; | |
double screenHeight = MediaQuery.of(context).size.height; | |
return Scaffold( | |
backgroundColor: Colors.white, | |
appBar: AppBar( | |
backgroundColor: Theme.of(context).primaryColor, | |
title: Text("Login"), | |
centerTitle: true, | |
), | |
body: Center( | |
child: OrientationBuilder(builder: (BuildContext context, orientation) { | |
return Card( | |
elevation: 10.0, | |
child: Container( | |
width: (orientation == Orientation.portrait) | |
? screenWidth | |
: screenHeight, | |
height: (orientation == Orientation.portrait) | |
? screenHeight / 1.75 | |
: screenWidth / 2, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Hero( | |
tag: widget.congregationName, | |
child: Card( | |
elevation: 4.0, | |
shape: CircleBorder(), | |
child: Image.network( | |
widget.imgSrc, | |
fit: BoxFit.fill, | |
width: (orientation == Orientation.portrait) | |
? (screenWidth / 2) // if it's portrait | |
: (screenHeight / 4), // if it's landscape | |
), | |
), | |
), | |
Padding( | |
padding: EdgeInsets.only(top: 10.0), | |
), | |
Text( | |
"${widget.congregationName}", | |
textAlign: TextAlign.center, | |
style: | |
TextStyle(fontWeight: FontWeight.w200, fontSize: 20.0), | |
), | |
Padding( | |
padding: const EdgeInsets.symmetric( | |
vertical: 8.0, horizontal: 30.0), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
TextField( | |
controller: _listPassController, | |
onChanged: (value) { | |
if (value.length > 0) { | |
setState(() { | |
_listPassFieldIsValid = true; | |
}); | |
} else if (_listPassFieldIsValid && | |
value.length == 0) { | |
setState(() { | |
_listPassFieldIsValid = false; | |
}); | |
} | |
debugPrint(_listPassFieldIsValid.toString()); | |
}, | |
keyboardType: TextInputType.number, | |
maxLength: 4, | |
decoration: InputDecoration(hintText: "Enter PIN"), | |
), | |
Padding( | |
padding: EdgeInsets.symmetric( | |
horizontal: screenWidth / 10)), | |
Row( | |
children: <Widget>[ | |
new Text("Enter the number of listeners: "), | |
Padding( | |
padding: | |
EdgeInsets.symmetric(horizontal: 10.0)), | |
DropdownButton<int>( | |
value: dropDownButtonValue, | |
isDense: true, | |
items: new List<DropdownMenuItem<int>>.generate( | |
10, | |
(i) => DropdownMenuItem<int>( | |
value: i, | |
child: Text("$i"), | |
)), | |
onChanged: (int value) { | |
setState(() { | |
dropDownButtonValue = value; | |
}); | |
}, | |
), | |
], | |
), | |
], | |
), | |
), | |
Padding( | |
padding: EdgeInsets.all(10.0), | |
), | |
RaisedButton( | |
color: Theme.of(context).primaryColor, | |
child: Text("Login"), | |
onPressed: !_listPassFieldIsValid | |
? null | |
: () => | |
login( | |
listPass: _listPassController.text, | |
numOfListeners: dropDownButtonValue) | |
) | |
], | |
), | |
), | |
color: Colors.white, | |
); | |
}), | |
), | |
); | |
} | |
Future login( | |
{@required String listPass, @required int numOfListeners}) async { | |
debugPrint('Login Button Pressed.'); | |
if (_listPassFieldIsValid) { | |
debugPrint("Login Field is valid"); | |
assert(widget.congregationName != null); | |
assert(widget.congregationUrl != null); | |
assert(widget.congregationId != null); | |
assert(listPass != null); | |
assert(numOfListeners != null); | |
debugPrint("Assertions Passed"); | |
debugPrint("ListPass: $listPass"); | |
debugPrint("NumOfListeners: $numOfListeners"); | |
Map loginResult = await widget.liveKH.login( | |
congregationId: widget.congregationId, | |
congregationName: widget.congregationName, | |
congregationUrl: widget.congregationUrl, | |
listPass: listPass); | |
if (loginResult['success']) { | |
String body = loginResult['response']?.body; | |
await Navigator | |
.of(context) | |
.push(new MaterialPageRoute(builder: (BuildContext context) { | |
return HallPage( | |
title: widget.congregationName, | |
body: body, | |
); | |
})); | |
widget.liveKH.logout(); | |
} else { | |
showErrorSnackbar(context); | |
} | |
} | |
} | |
void showErrorSnackbar(BuildContext context) { | |
SnackBar snackBar = SnackBar( | |
content: | |
Text("Login failed. Please check your password and try again")); | |
Scaffold.of(context).showSnackBar(snackBar); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stacktrace:
E/flutter ( 6830): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 6830): Failed assertion: boolean expression must not be null
E/flutter ( 6830): #0 _LoginPageState.login (file:///home/thinkdigital/IdeaProjects/livekh_flutter/lib/ui/login_page.dart)
E/flutter ( 6830):
E/flutter ( 6830): #1 _LoginPageState.build.. (file:///home/thinkdigital/IdeaProjects/livekh_flutter/lib/ui/login_page.dart:156:32) Shows error here on line 156, but the real error was on line 189
`loginResult['success']'should be loginResult['status']E/flutter ( 6830): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
E/flutter ( 6830): #3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:549:30)
E/flutter ( 6830): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 6830): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
E/flutter ( 6830): #6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
E/flutter ( 6830): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter ( 6830): #8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 6830): #9 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 6830): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter ( 6830): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter ( 6830): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 6830): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter ( 6830): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter ( 6830): #15 _invoke1 (dart:ui/hooks.dart:134:13)
E/flutter ( 6830): #16 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)