check null safety

This commit is contained in:
tzw
2021-09-10 16:33:52 +06:30
parent 3eacbef117
commit d8c86a512b
46 changed files with 275 additions and 304 deletions

View File

@@ -3,23 +3,12 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/user_search/user_serach.dart';
import 'package:flutter/material.dart';
class UserListRow extends StatefulWidget {
final OnUserRowSelect onUserRowSelect;
class UserListRow extends StatelessWidget {
final OnUserRowSelect? onUserRowSelect;
final User user;
const UserListRow({this.user, this.onUserRowSelect});
const UserListRow({required this.user, this.onUserRowSelect});
@override
_UserListRowState createState() => _UserListRowState();
}
class _UserListRowState extends State<UserListRow> {
final double dotSize = 15.0;
User user;
@override
void initState() {
super.initState();
this.user = widget.user;
}
@override
Widget build(BuildContext context) {
@@ -30,8 +19,7 @@ class _UserListRowState extends State<UserListRow> {
color: Colors.white,
child: InkWell(
onTap: () {
if (widget.onUserRowSelect != null)
widget.onUserRowSelect(widget.user);
if (onUserRowSelect != null) onUserRowSelect!(user);
},
child: Row(
children: <Widget>[
@@ -53,17 +41,17 @@ class _UserListRowState extends State<UserListRow> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(
user.name == null ? '' : user.name,
user.name ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.black),
),
new Text(
user.fcsID == null ? "" : user.fcsID,
user.fcsID ?? "",
style: new TextStyle(
fontSize: 13.0, color: Colors.grey),
),
new Text(
user.phoneNumber == null ? "" : user.phoneNumber,
user.phoneNumber ?? "",
style: new TextStyle(
fontSize: 13.0, color: Colors.grey),
),

View File

@@ -8,8 +8,8 @@ import 'package:provider/provider.dart';
typedef OnUserSelect(User suer);
typedef OnUserRowSelect(User suer);
Future<User> searchUser(BuildContext context,
{OnUserSelect onUserSelect, bool popPage = false}) async =>
Future<User?> searchUser(BuildContext context,
{required OnUserSelect onUserSelect, bool popPage = false}) async =>
await showSearch<User>(
context: context,
delegate:
@@ -20,7 +20,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
final OnUserSelect onUserSelect;
final bool popPage;
UserSearchDelegate({this.onUserSelect, this.popPage});
UserSearchDelegate({required this.onUserSelect, required this.popPage});
@override
String get searchFieldLabel => 'Search by FCS ID or Name';
@@ -31,10 +31,10 @@ class UserSearchDelegate extends SearchDelegate<User> {
return theme.copyWith(
inputDecorationTheme: InputDecorationTheme(
hintStyle: TextStyle(
color: theme.primaryTextTheme.caption.color, fontSize: 14)),
color: theme.primaryTextTheme.caption?.color, fontSize: 14)),
textTheme: theme.textTheme.copyWith(
title: theme.textTheme.title.copyWith(
color: theme.primaryTextTheme.title.color, fontSize: 16)),
title: theme.textTheme.title?.copyWith(
color: theme.primaryTextTheme.title?.color, fontSize: 16)),
primaryColor: primaryColor,
);
}
@@ -53,7 +53,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
Widget buildLeading(BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => close(context, null),
onPressed: () => close(context, new User()),
);
}
@@ -64,7 +64,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
future: packageModel.searchUser(query),
builder: (context, AsyncSnapshot<List<User>> snapshot) {
if (snapshot.hasData) {
if (snapshot.data.length == 0) {
if (snapshot.data == null || snapshot.data!.length == 0) {
return Container(
child: Center(
child: Text(
@@ -77,7 +77,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
return Container(
padding: EdgeInsets.only(top: 15),
child: ListView(
children: snapshot.data
children: snapshot.data!
.map((u) => UserListRow(
user: u,
onUserRowSelect: (u) => _onUserRowSelect(context, u),