refactor: Migrate utils and main.dart to null safety

This commit is contained in:
Krille Fear 2021-11-19 20:15:07 +01:00
parent c64d831f25
commit 97a880d6c8
7 changed files with 39 additions and 22 deletions

View File

@ -12,6 +12,7 @@ linter:
analyzer: analyzer:
errors: errors:
todo: ignore todo: ignore
import_of_legacy_library_into_null_safe: ignore
exclude: exclude:
- lib/generated_plugin_registrant.dart - lib/generated_plugin_registrant.dart
- lib/l10n/*.dart - lib/l10n/*.dart

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'dart:ui'; import 'dart:ui';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
@ -5,8 +7,8 @@ import 'package:matrix/matrix.dart';
abstract class AppConfig { abstract class AppConfig {
static String _applicationName = 'FluffyChat'; static String _applicationName = 'FluffyChat';
static String get applicationName => _applicationName; static String get applicationName => _applicationName;
static String _applicationWelcomeMessage; static String? _applicationWelcomeMessage;
static String get applicationWelcomeMessage => _applicationWelcomeMessage; static String? get applicationWelcomeMessage => _applicationWelcomeMessage;
static String _defaultHomeserver = 'matrix.org'; static String _defaultHomeserver = 'matrix.org';
static String get defaultHomeserver => _defaultHomeserver; static String get defaultHomeserver => _defaultHomeserver;
static String jitsiInstance = 'https://meet.jit.si/'; static String jitsiInstance = 'https://meet.jit.si/';

View File

@ -1,3 +1,5 @@
//@dart=2.12
abstract class AppEmojis { abstract class AppEmojis {
static const List<String> emojis = [ static const List<String> emojis = [
'👍', '👍',

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:vrouter/vrouter.dart'; import 'package:vrouter/vrouter.dart';
@ -341,7 +343,7 @@ class AppRoutes {
), ),
]; ];
FadeTransition Function(dynamic, dynamic, dynamic) get _dynamicTransition => FadeTransition Function(dynamic, dynamic, dynamic)? get _dynamicTransition =>
columnMode ? _fadeTransition : null; columnMode ? _fadeTransition : null;
FadeTransition _fadeTransition(animation1, _, child) => FadeTransition _fadeTransition(animation1, _, child) =>

View File

@ -1,3 +1,5 @@
//@dart=2.12
abstract class SettingKeys { abstract class SettingKeys {
static const String jitsiInstance = 'chat.fluffy.jitsi_instance'; static const String jitsiInstance = 'chat.fluffy.jitsi_instance';
static const String wallpaper = 'chat.fluffy.wallpaper'; static const String wallpaper = 'chat.fluffy.wallpaper';

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';

View File

@ -1,4 +1,4 @@
// @dart=2.9 // @dart=2.12
import 'dart:async'; import 'dart:async';
@ -33,8 +33,11 @@ void main() async {
// To make sure that the parts of flutter needed are started up already, we need to ensure that the // To make sure that the parts of flutter needed are started up already, we need to ensure that the
// widget bindings are initialized already. // widget bindings are initialized already.
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (FlutterErrorDetails details) => FlutterError.onError =
Zone.current.handleUncaughtError(details.exception, details.stack); (FlutterErrorDetails details) => Zone.current.handleUncaughtError(
details.exception,
details.stack ?? StackTrace.current,
);
final clients = await ClientManager.getClients(); final clients = await ClientManager.getClients();
Logs().level = kReleaseMode ? Level.warning : Level.verbose; Logs().level = kReleaseMode ? Level.warning : Level.verbose;
@ -65,13 +68,16 @@ void main() async {
} }
class FluffyChatApp extends StatefulWidget { class FluffyChatApp extends StatefulWidget {
final Widget testWidget; final Widget? testWidget;
final List<Client> clients; final List<Client> clients;
final Map<String, String> queryParameters; final Map<String, String>? queryParameters;
const FluffyChatApp( const FluffyChatApp({
{Key key, this.testWidget, @required this.clients, this.queryParameters}) Key? key,
: super(key: key); this.testWidget,
required this.clients,
this.queryParameters,
}) : super(key: key);
/// getInitialLink may rereturn the value multiple times if this view is /// getInitialLink may rereturn the value multiple times if this view is
/// opened multiple times for example if the user logs out after they logged /// opened multiple times for example if the user logs out after they logged
@ -83,9 +89,9 @@ class FluffyChatApp extends StatefulWidget {
} }
class _FluffyChatAppState extends State<FluffyChatApp> { class _FluffyChatAppState extends State<FluffyChatApp> {
GlobalKey<VRouterState> _router; GlobalKey<VRouterState>? _router;
bool columnMode; bool? columnMode;
String _initialUrl; String? _initialUrl;
@override @override
void initState() { void initState() {
@ -110,9 +116,9 @@ class _FluffyChatAppState extends State<FluffyChatApp> {
_router ??= GlobalKey<VRouterState>(); _router ??= GlobalKey<VRouterState>();
if (columnMode != newColumns > 1) { if (columnMode != newColumns > 1) {
Logs().v('Set Column Mode = $columnMode'); Logs().v('Set Column Mode = $columnMode');
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance?.addPostFrameCallback((_) {
setState(() { setState(() {
_initialUrl = _router.currentState.url; _initialUrl = _router?.currentState?.url;
columnMode = newColumns > 1; columnMode = newColumns > 1;
_router = GlobalKey<VRouterState>(); _router = GlobalKey<VRouterState>();
}); });
@ -127,17 +133,17 @@ class _FluffyChatAppState extends State<FluffyChatApp> {
darkTheme: darkTheme, darkTheme: darkTheme,
localizationsDelegates: L10n.localizationsDelegates, localizationsDelegates: L10n.localizationsDelegates,
supportedLocales: L10n.supportedLocales, supportedLocales: L10n.supportedLocales,
initialUrl: _initialUrl, initialUrl: _initialUrl ?? '/',
locale: kIsWeb locale: kIsWeb
? Locale(html.window.navigator.language.split('-').first) ? Locale(html.window.navigator.language.split('-').first)
: null, : null,
routes: AppRoutes(columnMode).routes, routes: AppRoutes(columnMode ?? false).routes,
builder: (context, child) { builder: (context, child) {
LoadingDialog.defaultTitle = L10n.of(context).loadingPleaseWait; LoadingDialog.defaultTitle = L10n.of(context)!.loadingPleaseWait;
LoadingDialog.defaultBackLabel = L10n.of(context).close; LoadingDialog.defaultBackLabel = L10n.of(context)!.close;
LoadingDialog.defaultOnError = LoadingDialog.defaultOnError =
(Object e) => e.toLocalizedString(context); (e) => (e as Object).toLocalizedString(context);
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance?.addPostFrameCallback((_) {
SystemChrome.setSystemUIOverlayStyle( SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle( SystemUiOverlayStyle(
statusBarColor: Colors.transparent, statusBarColor: Colors.transparent,