mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
Update example to sound null safety
This commit is contained in:
@ -34,13 +34,13 @@ class SignInDemo extends StatefulWidget {
|
|||||||
|
|
||||||
/// The state of the main widget.
|
/// The state of the main widget.
|
||||||
class SignInDemoState extends State<SignInDemo> {
|
class SignInDemoState extends State<SignInDemo> {
|
||||||
GoogleSignInAccount _currentUser;
|
GoogleSignInAccount? _currentUser;
|
||||||
String _contactText;
|
String? _contactText;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) {
|
_googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount? account) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentUser = account;
|
_currentUser = account;
|
||||||
});
|
});
|
||||||
@ -57,14 +57,14 @@ class SignInDemoState extends State<SignInDemo> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final PeopleServiceApi peopleApi =
|
final PeopleServiceApi peopleApi =
|
||||||
PeopleServiceApi(await _googleSignIn.authenticatedClient());
|
PeopleServiceApi((await _googleSignIn.authenticatedClient())!);
|
||||||
final ListConnectionsResponse response =
|
final ListConnectionsResponse response =
|
||||||
await peopleApi.people.connections.list(
|
await peopleApi.people.connections.list(
|
||||||
'people/me',
|
'people/me',
|
||||||
personFields: 'names',
|
personFields: 'names',
|
||||||
);
|
);
|
||||||
|
|
||||||
final String firstNamedContactName =
|
final String? firstNamedContactName =
|
||||||
_pickFirstNamedContact(response.connections);
|
_pickFirstNamedContact(response.connections);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -76,18 +76,16 @@ class SignInDemoState extends State<SignInDemo> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String _pickFirstNamedContact(List<Person> connections) {
|
String? _pickFirstNamedContact(List<Person>? connections) {
|
||||||
return connections
|
return connections
|
||||||
?.firstWhere(
|
?.firstWhere(
|
||||||
(Person person) => person.names != null,
|
(Person person) => person.names != null,
|
||||||
orElse: () => null,
|
|
||||||
)
|
)
|
||||||
?.names
|
.names
|
||||||
?.firstWhere(
|
?.firstWhere(
|
||||||
(Name name) => name.displayName != null,
|
(Name name) => name.displayName != null,
|
||||||
orElse: () => null,
|
|
||||||
)
|
)
|
||||||
?.displayName;
|
.displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleSignIn() async {
|
Future<void> _handleSignIn() async {
|
||||||
@ -107,10 +105,10 @@ class SignInDemoState extends State<SignInDemo> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: GoogleUserCircleAvatar(
|
leading: GoogleUserCircleAvatar(
|
||||||
identity: _currentUser,
|
identity: _currentUser!,
|
||||||
),
|
),
|
||||||
title: Text(_currentUser.displayName ?? ''),
|
title: Text(_currentUser!.displayName ?? ''),
|
||||||
subtitle: Text(_currentUser.email ?? ''),
|
subtitle: Text(_currentUser!.email),
|
||||||
),
|
),
|
||||||
const Text('Signed in successfully.'),
|
const Text('Signed in successfully.'),
|
||||||
Text(_contactText ?? ''),
|
Text(_contactText ?? ''),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
name: extension_google_sign_in_example
|
name: extension_google_sign_in_example
|
||||||
description: Example of Google Sign-In plugin and googleapis.
|
description: Example of Google Sign-In plugin and googleapis.
|
||||||
|
publish_to: none
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
extension_google_sign_in_as_googleapis_auth:
|
extension_google_sign_in_as_googleapis_auth:
|
||||||
@ -12,7 +13,7 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
google_sign_in: ^5.0.0
|
google_sign_in: ^5.0.0
|
||||||
googleapis: ^1.0.0
|
googleapis: ^2.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
pedantic: ^1.10.0
|
pedantic: ^1.10.0
|
||||||
@ -21,5 +22,5 @@ flutter:
|
|||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.0.0-dev.28.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
flutter: ">=1.12.13+hotfix.4"
|
flutter: ">=1.20.0"
|
||||||
|
Reference in New Issue
Block a user