Implemented Null Safety.

This commit is contained in:
Phani Pavan K
2021-02-18 15:41:13 +05:30
parent 56f5210712
commit 0e792ea48f
10 changed files with 402 additions and 39 deletions

View File

@@ -22,7 +22,7 @@ class MyApp extends StatelessWidget {
class LoginPage extends StatefulWidget {
final VoidCallback _onSignIn;
LoginPage({@required onSignIn})
LoginPage({required onSignIn})
: assert(onSignIn != null),
_onSignIn = onSignIn;
@@ -40,13 +40,13 @@ class _LoginPageState extends State<LoginPage> {
bool _isInvalidAsyncUser = false; // managed after response from server
bool _isInvalidAsyncPass = false; // managed after response from server
String _username;
String _password;
String? _username;
String? _password;
bool _isLoggedIn = false;
// validate user name
String _validateUserName(String userName) {
if (userName.length < 8) {
String? _validateUserName(String? userName) {
if (userName!.length < 8) {
return 'Username must be at least 8 characters';
}
@@ -60,8 +60,8 @@ class _LoginPageState extends State<LoginPage> {
}
// validate password
String _validatePassword(String password) {
if (password.length < 8) {
String? _validatePassword(String? password) {
if (password!.length < 8) {
return 'Password must be at least 8 characters';
}
@@ -75,8 +75,8 @@ class _LoginPageState extends State<LoginPage> {
}
void _submit() {
if (_loginFormKey.currentState.validate()) {
_loginFormKey.currentState.save();
if (_loginFormKey.currentState!.validate()) {
_loginFormKey.currentState!.save();
// dismiss keyboard during async call
FocusScope.of(context).requestFocus(new FocusNode());
@@ -154,7 +154,7 @@ class _LoginPageState extends State<LoginPage> {
key: Key('username'),
decoration: InputDecoration(
hintText: 'enter username', labelText: 'User Name'),
style: TextStyle(fontSize: 20.0, color: textTheme.button.color),
style: TextStyle(fontSize: 20.0, color: textTheme.button!.color),
validator: _validateUserName,
onSaved: (value) => _username = value,
),
@@ -166,7 +166,7 @@ class _LoginPageState extends State<LoginPage> {
obscureText: true,
decoration: InputDecoration(
hintText: 'enter password', labelText: 'Password'),
style: TextStyle(fontSize: 20.0, color: textTheme.button.color),
style: TextStyle(fontSize: 20.0, color: textTheme.button!.color),
validator: _validatePassword,
onSaved: (value) => _password = value,
),

View File

@@ -157,5 +157,5 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"

View File

@@ -6,7 +6,7 @@ description: Demonstrates how to use the modal_progress_hud_nsn plugin.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter:

View File

@@ -19,7 +19,7 @@ void main() {
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);