Update example to sound null safety

This commit is contained in:
David Iglesias Teixeira
2021-03-08 13:31:23 -08:00
parent 8256805c57
commit eba7f33ff0
2 changed files with 15 additions and 16 deletions

View File

@ -34,13 +34,13 @@ class SignInDemo extends StatefulWidget {
/// The state of the main widget.
class SignInDemoState extends State<SignInDemo> {
GoogleSignInAccount _currentUser;
String _contactText;
GoogleSignInAccount? _currentUser;
String? _contactText;
@override
void initState() {
super.initState();
_googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) {
_googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount? account) {
setState(() {
_currentUser = account;
});
@ -57,14 +57,14 @@ class SignInDemoState extends State<SignInDemo> {
});
final PeopleServiceApi peopleApi =
PeopleServiceApi(await _googleSignIn.authenticatedClient());
PeopleServiceApi((await _googleSignIn.authenticatedClient())!);
final ListConnectionsResponse response =
await peopleApi.people.connections.list(
'people/me',
personFields: 'names',
);
final String firstNamedContactName =
final String? firstNamedContactName =
_pickFirstNamedContact(response.connections);
setState(() {
@ -76,18 +76,16 @@ class SignInDemoState extends State<SignInDemo> {
});
}
String _pickFirstNamedContact(List<Person> connections) {
String? _pickFirstNamedContact(List<Person>? connections) {
return connections
?.firstWhere(
(Person person) => person.names != null,
orElse: () => null,
)
?.names
.names
?.firstWhere(
(Name name) => name.displayName != null,
orElse: () => null,
)
?.displayName;
.displayName;
}
Future<void> _handleSignIn() async {
@ -107,10 +105,10 @@ class SignInDemoState extends State<SignInDemo> {
children: <Widget>[
ListTile(
leading: GoogleUserCircleAvatar(
identity: _currentUser,
identity: _currentUser!,
),
title: Text(_currentUser.displayName ?? ''),
subtitle: Text(_currentUser.email ?? ''),
title: Text(_currentUser!.displayName ?? ''),
subtitle: Text(_currentUser!.email),
),
const Text('Signed in successfully.'),
Text(_contactText ?? ''),

View File

@ -1,5 +1,6 @@
name: extension_google_sign_in_example
description: Example of Google Sign-In plugin and googleapis.
publish_to: none
dependencies:
extension_google_sign_in_as_googleapis_auth:
@ -12,7 +13,7 @@ dependencies:
flutter:
sdk: flutter
google_sign_in: ^5.0.0
googleapis: ^1.0.0
googleapis: ^2.0.0
dev_dependencies:
pedantic: ^1.10.0
@ -21,5 +22,5 @@ flutter:
uses-material-design: true
environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.12.13+hotfix.4"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"