refactor: Migrate to null safety

This commit is contained in:
Krille Fear 2022-01-29 12:35:03 +01:00 committed by Christian Pauly
commit 55f0300f9f
163 changed files with 1759 additions and 1903 deletions

View file

@ -21,7 +21,7 @@ import '../../main.dart';
import '../../utils/localized_exception_extension.dart';
class HomeserverPicker extends StatefulWidget {
const HomeserverPicker({Key key}) : super(key: key);
const HomeserverPicker({Key? key}) : super(key: key);
@override
HomeserverPickerController createState() => HomeserverPickerController();
@ -32,9 +32,9 @@ class HomeserverPickerController extends State<HomeserverPicker> {
String domain = AppConfig.defaultHomeserver;
final TextEditingController homeserverController =
TextEditingController(text: AppConfig.defaultHomeserver);
StreamSubscription _intentDataStreamSubscription;
String error;
Timer _coolDown;
StreamSubscription? _intentDataStreamSubscription;
String? error;
Timer? _coolDown;
void setDomain(String domain) {
this.domain = domain;
@ -46,7 +46,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
}
void _loginWithToken(String token) {
if (token?.isEmpty ?? true) return;
if (token.isEmpty) return;
showFutureLoadingDialog(
context: context,
@ -66,7 +66,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
);
}
void _processIncomingUris(String text) async {
void _processIncomingUris(String? text) async {
if (text == null || !text.startsWith(AppConfig.appOpenUrlScheme)) return;
await browser?.close();
VRouter.of(context).to('/home');
@ -89,8 +89,8 @@ class HomeserverPickerController extends State<HomeserverPicker> {
super.initState();
_initReceiveUri();
if (kIsWeb) {
WidgetsBinding.instance.addPostFrameCallback((_) {
final token = Matrix.of(context).widget.queryParameters['loginToken'];
WidgetsBinding.instance!.addPostFrameCallback((_) {
final token = Matrix.of(context).widget.queryParameters!['loginToken'];
if (token != null) _loginWithToken(token);
});
}
@ -103,7 +103,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
_intentDataStreamSubscription?.cancel();
}
String _lastCheckedHomeserver;
String? _lastCheckedHomeserver;
/// Starts an analysis of the given homeserver. It uses the current domain and
/// makes sure that it is prefixed with https. Then it searches for the
@ -112,7 +112,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
Future<void> checkHomeserverAction() async {
_coolDown?.cancel();
if (_lastCheckedHomeserver == domain) return;
if (domain.isEmpty) throw L10n.of(context).changeTheHomeserver;
if (domain.isEmpty) throw L10n.of(context)!.changeTheHomeserver;
var homeserver = domain;
if (!homeserver.startsWith('https://')) {
@ -129,7 +129,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
await Matrix.of(context).getLoginClient().checkHomeserver(homeserver);
var jitsi = wellKnown?.additionalProperties
?.tryGet<Map<String, dynamic>>('im.vector.riot.jitsi')
.tryGet<Map<String, dynamic>>('im.vector.riot.jitsi')
?.tryGet<String>('preferredDomain');
if (jitsi != null) {
if (!jitsi.endsWith('/')) {
@ -150,10 +150,10 @@ class HomeserverPickerController extends State<HomeserverPicker> {
await Matrix.of(context).getLoginClient().register();
registrationSupported = true;
} on MatrixException catch (e) {
registrationSupported = e.requireAdditionalAuthentication ?? false;
registrationSupported = e.requireAdditionalAuthentication;
}
} catch (e) {
setState(() => error = (e as Object).toLocalizedString(context));
setState(() => error = (e).toLocalizedString(context));
} finally {
_lastCheckedHomeserver = domain;
if (mounted) {
@ -162,12 +162,12 @@ class HomeserverPickerController extends State<HomeserverPicker> {
}
}
Map<String, dynamic> _rawLoginTypes;
bool registrationSupported;
Map<String, dynamic>? _rawLoginTypes;
bool? registrationSupported;
List<IdentityProvider> get identityProviders {
if (!ssoLoginSupported) return [];
final rawProviders = _rawLoginTypes.tryGetList('flows').singleWhere(
final rawProviders = _rawLoginTypes!.tryGetList('flows')!.singleWhere(
(flow) =>
flow['type'] == AuthenticationTypes.sso)['identity_providers'];
final list = (rawProviders as List)
@ -184,8 +184,8 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.client
.supportedLoginTypes
.contains(AuthenticationTypes.password) &&
_rawLoginTypes
.tryGetList('flows')
_rawLoginTypes!
.tryGetList('flows')!
.any((flow) => flow['type'] == AuthenticationTypes.password);
bool get ssoLoginSupported =>
@ -193,11 +193,11 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.client
.supportedLoginTypes
.contains(AuthenticationTypes.sso) &&
_rawLoginTypes
.tryGetList('flows')
_rawLoginTypes!
.tryGetList('flows')!
.any((flow) => flow['type'] == AuthenticationTypes.sso);
ChromeSafariBrowser browser;
ChromeSafariBrowser? browser;
static const String ssoHomeserverKey = 'sso-homeserver';
@ -215,7 +215,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
'${Matrix.of(context).getLoginClient().homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}';
if (PlatformInfos.isMobile) {
browser ??= ChromeSafariBrowser();
browser.open(url: Uri.parse(url));
browser!.open(url: Uri.parse(url));
} else {
launch(redirectUrl);
}
@ -234,10 +234,10 @@ class HomeserverPickerController extends State<HomeserverPicker> {
}
class IdentityProvider {
final String id;
final String name;
final String icon;
final String brand;
final String? id;
final String? name;
final String? icon;
final String? brand;
IdentityProvider({this.id, this.name, this.icon, this.brand});

View file

@ -17,7 +17,7 @@ import 'homeserver_picker.dart';
class HomeserverPickerView extends StatelessWidget {
final HomeserverPickerController controller;
const HomeserverPickerView(this.controller, {Key key}) : super(key: key);
const HomeserverPickerView(this.controller, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -27,7 +27,7 @@ class HomeserverPickerView extends StatelessWidget {
titleSpacing: 8,
title: DefaultAppBarSearchField(
prefixText: 'https://',
hintText: L10n.of(context).enterYourHomeserver,
hintText: L10n.of(context)!.enterYourHomeserver,
searchController: controller.homeserverController,
suffix: const Icon(Icons.edit_outlined),
padding: EdgeInsets.zero,
@ -36,7 +36,7 @@ class HomeserverPickerView extends StatelessWidget {
onSubmit: (_) => controller.checkHomeserverAction(),
unfocusOnClear: false,
autocorrect: false,
labelText: L10n.of(context).homeserver,
labelText: L10n.of(context)!.homeserver,
),
elevation: 0,
),
@ -54,7 +54,7 @@ class HomeserverPickerView extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
controller.error,
controller.error!,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
@ -77,7 +77,7 @@ class HomeserverPickerView extends StatelessWidget {
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).loginWithOneClick),
child: Text(L10n.of(context)!.loginWithOneClick),
),
const Expanded(child: Divider()),
]),
@ -88,20 +88,20 @@ class HomeserverPickerView extends StatelessWidget {
in controller.identityProviders)
_SsoButton(
onPressed: () =>
controller.ssoLoginAction(identityProvider.id),
controller.ssoLoginAction(identityProvider.id!),
identityProvider: identityProvider,
),
},
].toList(),
),
if (controller.ssoLoginSupported &&
(controller.registrationSupported ||
(controller.registrationSupported! ||
controller.passwordLoginSupported))
Row(children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
child: Text(L10n.of(context)!.or),
),
const Expanded(child: Divider()),
]),
@ -111,22 +111,22 @@ class HomeserverPickerView extends StatelessWidget {
onPressed: () => VRouter.of(context).to('login'),
icon: Icon(
CupertinoIcons.lock_open_fill,
color: Theme.of(context).textTheme.bodyText1.color,
color: Theme.of(context).textTheme.bodyText1!.color,
),
labelText: L10n.of(context).login,
labelText: L10n.of(context)!.login,
),
),
const SizedBox(height: 12),
],
if (controller.registrationSupported)
if (controller.registrationSupported!)
Center(
child: _LoginButton(
onPressed: controller.signUpAction,
icon: Icon(
CupertinoIcons.person_add,
color: Theme.of(context).textTheme.bodyText1.color,
color: Theme.of(context).textTheme.bodyText1!.color,
),
labelText: L10n.of(context).register,
labelText: L10n.of(context)!.register,
),
),
],
@ -142,7 +142,7 @@ class HomeserverPickerView extends StatelessWidget {
TextButton(
onPressed: () => launch(AppConfig.privacyUrl),
child: Text(
L10n.of(context).privacy,
L10n.of(context)!.privacy,
style: const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueGrey,
@ -152,7 +152,7 @@ class HomeserverPickerView extends StatelessWidget {
TextButton(
onPressed: () => PlatformInfos.showDialog(context),
child: Text(
L10n.of(context).about,
L10n.of(context)!.about,
style: const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueGrey,
@ -169,10 +169,10 @@ class HomeserverPickerView extends StatelessWidget {
class _SsoButton extends StatelessWidget {
final IdentityProvider identityProvider;
final void Function() onPressed;
final void Function()? onPressed;
const _SsoButton({
Key key,
@required this.identityProvider,
Key? key,
required this.identityProvider,
this.onPressed,
}) : super(key: key);
@ -196,7 +196,7 @@ class _SsoButton extends StatelessWidget {
child: identityProvider.icon == null
? const Icon(Icons.web_outlined)
: CachedNetworkImage(
imageUrl: Uri.parse(identityProvider.icon)
imageUrl: Uri.parse(identityProvider.icon!)
.getDownloadLink(
Matrix.of(context).getLoginClient())
.toString(),
@ -209,11 +209,11 @@ class _SsoButton extends StatelessWidget {
Text(
identityProvider.name ??
identityProvider.brand ??
L10n.of(context).singlesignon,
L10n.of(context)!.singlesignon,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).textTheme.subtitle2.color,
color: Theme.of(context).textTheme.subtitle2!.color,
),
),
],
@ -224,11 +224,11 @@ class _SsoButton extends StatelessWidget {
}
class _LoginButton extends StatelessWidget {
final String labelText;
final Widget icon;
final void Function() onPressed;
final String? labelText;
final Widget? icon;
final void Function()? onPressed;
const _LoginButton({
Key key,
Key? key,
this.labelText,
this.icon,
this.onPressed,
@ -246,11 +246,11 @@ class _LoginButton extends StatelessWidget {
),
),
onPressed: onPressed,
icon: icon,
icon: icon!,
label: Text(
labelText,
labelText!,
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
color: Theme.of(context).textTheme.bodyText1!.color,
),
),
);