refactor: Make layouts null safe

This commit is contained in:
Krille Fear 2021-11-19 20:28:17 +01:00
parent aaf67c8f70
commit 3f10c0bae6
6 changed files with 36 additions and 27 deletions

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'dart:math';
import 'package:flutter/material.dart';
@ -5,7 +7,7 @@ import 'package:flutter/material.dart';
class EmptyPage extends StatelessWidget {
final bool loading;
static const double _width = 200;
const EmptyPage({this.loading = false, Key key}) : super(key: key);
const EmptyPage({this.loading = false, Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final _width = min(MediaQuery.of(context).size.width, EmptyPage._width);

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
@ -7,15 +9,11 @@ import 'package:fluffychat/widgets/layouts/empty_page.dart';
import 'package:fluffychat/widgets/matrix.dart';
class LoadingView extends StatelessWidget {
const LoadingView({Key key}) : super(key: key);
const LoadingView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
if (Matrix.of(context)
.widget
.clients
.every((client) => client.loginState != null)) {
WidgetsBinding.instance.addPostFrameCallback(
WidgetsBinding.instance?.addPostFrameCallback(
(_) => VRouter.of(context).to(
Matrix.of(context)
.widget
@ -26,7 +24,6 @@ class LoadingView extends StatelessWidget {
queryParameters: VRouter.of(context).queryParameters,
),
);
}
return const EmptyPage(loading: true);
}
}

View File

@ -1,9 +1,11 @@
//@dart=2.12
import 'dart:math';
import 'package:flutter/material.dart';
class MaxWidthBody extends StatelessWidget {
final Widget child;
final Widget? child;
final double maxWidth;
final bool withScrolling;
@ -11,7 +13,7 @@ class MaxWidthBody extends StatelessWidget {
this.child,
this.maxWidth = 600,
this.withScrolling = false,
Key key,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'dart:math';
import 'package:flutter/material.dart';
@ -8,14 +10,14 @@ import 'package:fluffychat/widgets/matrix.dart';
class OnePageCard extends StatelessWidget {
final Widget child;
const OnePageCard({Key key, this.child}) : super(key: key);
const OnePageCard({Key? key, required this.child}) : super(key: key);
static const int alpha = 12;
static num breakpoint = FluffyThemes.columnWidth * 2;
@override
Widget build(BuildContext context) {
final horizontalPadding =
max((MediaQuery.of(context).size.width - 600) / 2, 24);
max<double>((MediaQuery.of(context).size.width - 600) / 2, 24);
return MediaQuery.of(context).size.width <= breakpoint ||
Matrix.of(context).client.isLogged()
? child

View File

@ -1,3 +1,5 @@
//@dart=2.12
import 'package:flutter/material.dart';
import 'package:vrouter/vrouter.dart';
@ -6,15 +8,16 @@ import 'package:fluffychat/config/themes.dart';
class SideViewLayout extends StatelessWidget {
final Widget mainView;
final Widget sideView;
final Widget? sideView;
const SideViewLayout({Key key, @required this.mainView, this.sideView})
const SideViewLayout({Key? key, required this.mainView, this.sideView})
: super(key: key);
@override
Widget build(BuildContext context) {
var currentUrl = Uri.decodeFull(VRouter.of(context).url);
if (!currentUrl.endsWith('/')) currentUrl += '/';
final hideSideView = currentUrl.split('/').length == 4;
final sideView = this.sideView;
return sideView == null
? mainView
: MediaQuery.of(context).size.width < FluffyThemes.columnWidth * 3.5 &&

View File

@ -1,3 +1,4 @@
//@dart=2.12
import 'package:flutter/material.dart';
import 'package:fluffychat/config/themes.dart';
@ -6,9 +7,11 @@ class TwoColumnLayout extends StatelessWidget {
final Widget mainView;
final Widget sideView;
const TwoColumnLayout(
{Key key, @required this.mainView, @required this.sideView})
: super(key: key);
const TwoColumnLayout({
Key? key,
required this.mainView,
required this.sideView,
}) : super(key: key);
@override
Widget build(BuildContext context) {
if (MediaQuery.of(context).size.width <= FluffyThemes.columnWidth * 2) {