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

@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/localized_exception_extension.dart';
class SignupPage extends StatefulWidget {
const SignupPage({Key key}) : super(key: key);
const SignupPage({Key? key}) : super(key: key);
@override
SignupPageController createState() => SignupPageController();
@ -20,49 +20,49 @@ class SignupPageController extends State<SignupPage> {
final TextEditingController passwordController = TextEditingController();
final TextEditingController passwordController2 = TextEditingController();
final TextEditingController emailController = TextEditingController();
String error;
String? error;
bool loading = false;
bool showPassword = false;
void toggleShowPassword() => setState(() => showPassword = !showPassword);
String get domain => VRouter.of(context).queryParameters['domain'];
String? get domain => VRouter.of(context).queryParameters['domain'];
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
String usernameTextFieldValidator(String value) {
String? usernameTextFieldValidator(String? value) {
usernameController.text =
usernameController.text.trim().toLowerCase().replaceAll(' ', '_');
if (value.isEmpty) {
return L10n.of(context).pleaseChooseAUsername;
if (value!.isEmpty) {
return L10n.of(context)!.pleaseChooseAUsername;
}
return null;
}
String password1TextFieldValidator(String value) {
String? password1TextFieldValidator(String? value) {
const minLength = 8;
if (value.isEmpty) {
return L10n.of(context).chooseAStrongPassword;
if (value!.isEmpty) {
return L10n.of(context)!.chooseAStrongPassword;
}
if (value.length < minLength) {
return L10n.of(context).pleaseChooseAtLeastChars(minLength.toString());
return L10n.of(context)!.pleaseChooseAtLeastChars(minLength.toString());
}
return null;
}
String password2TextFieldValidator(String value) {
if (value.isEmpty) {
return L10n.of(context).chooseAStrongPassword;
String? password2TextFieldValidator(String? value) {
if (value!.isEmpty) {
return L10n.of(context)!.chooseAStrongPassword;
}
if (value != passwordController.text) {
return L10n.of(context).passwordsDoNotMatch;
return L10n.of(context)!.passwordsDoNotMatch;
}
return null;
}
String emailTextFieldValidator(String value) {
if (value.isNotEmpty && !value.contains('@')) {
return L10n.of(context).pleaseEnterValidEmail;
String? emailTextFieldValidator(String? value) {
if (value!.isNotEmpty && !value.contains('@')) {
return L10n.of(context)!.pleaseEnterValidEmail;
}
return null;
}
@ -71,7 +71,7 @@ class SignupPageController extends State<SignupPage> {
setState(() {
error = null;
});
if (!formKey.currentState.validate()) return;
if (!formKey.currentState!.validate()) return;
setState(() {
loading = true;
@ -99,7 +99,7 @@ class SignupPageController extends State<SignupPage> {
),
);
} catch (e) {
error = (e as Object).toLocalizedString(context);
error = (e).toLocalizedString(context);
} finally {
if (mounted) {
setState(() => loading = false);

View file

@ -7,14 +7,14 @@ import 'signup.dart';
class SignupPageView extends StatelessWidget {
final SignupPageController controller;
const SignupPageView(this.controller, {Key key}) : super(key: key);
const SignupPageView(this.controller, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return OnePageCard(
child: Scaffold(
appBar: AppBar(
title: Text(L10n.of(context).signUp),
title: Text(L10n.of(context)!.signUp),
),
body: Form(
key: controller.formKey,
@ -31,8 +31,8 @@ class SignupPageView extends StatelessWidget {
validator: controller.usernameTextFieldValidator,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.account_circle_outlined),
hintText: L10n.of(context).username,
labelText: L10n.of(context).username,
hintText: L10n.of(context)!.username,
labelText: L10n.of(context)!.username,
prefixText: '@',
prefixStyle: const TextStyle(fontWeight: FontWeight.bold),
suffixStyle: const TextStyle(fontWeight: FontWeight.w200),
@ -53,13 +53,13 @@ class SignupPageView extends StatelessWidget {
prefixIcon: const Icon(Icons.vpn_key_outlined),
hintText: '****',
suffixIcon: IconButton(
tooltip: L10n.of(context).showPassword,
tooltip: L10n.of(context)!.showPassword,
icon: Icon(controller.showPassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined),
onPressed: controller.toggleShowPassword,
),
labelText: L10n.of(context).password,
labelText: L10n.of(context)!.password,
),
),
),
@ -76,7 +76,7 @@ class SignupPageView extends StatelessWidget {
decoration: InputDecoration(
prefixIcon: const Icon(Icons.repeat_outlined),
hintText: '****',
labelText: L10n.of(context).repeatPassword,
labelText: L10n.of(context)!.repeatPassword,
),
),
),
@ -92,7 +92,7 @@ class SignupPageView extends StatelessWidget {
validator: controller.emailTextFieldValidator,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.mail_outlined),
labelText: L10n.of(context).addEmail,
labelText: L10n.of(context)!.addEmail,
hintText: 'email@example.abc',
),
),
@ -103,7 +103,7 @@ class SignupPageView extends StatelessWidget {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
controller.error,
controller.error!,
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
),
@ -120,7 +120,7 @@ class SignupPageView extends StatelessWidget {
onPressed: controller.loading ? null : controller.signup,
child: controller.loading
? const LinearProgressIndicator()
: Text(L10n.of(context).signUp),
: Text(L10n.of(context)!.signUp),
),
),
),