mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 14:59:29 +01:00
refactor: Make more files null safe
This commit is contained in:
parent
4ef1e53494
commit
3c4347b5e8
@ -1,3 +1,5 @@
|
||||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
@ -9,30 +11,33 @@ import 'package:fluffychat/pages/archive/archive_view.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class Archive extends StatefulWidget {
|
||||
const Archive({Key key}) : super(key: key);
|
||||
const Archive({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
ArchiveController createState() => ArchiveController();
|
||||
}
|
||||
|
||||
class ArchiveController extends State<Archive> {
|
||||
List<Room> archive;
|
||||
List<Room>? archive;
|
||||
|
||||
Future<List<Room>> getArchive(BuildContext context) async {
|
||||
final archive = this.archive;
|
||||
if (archive != null) return archive;
|
||||
return await Matrix.of(context).client.loadArchive();
|
||||
}
|
||||
|
||||
void forgetAction(int i) => setState(() => archive.removeAt(i));
|
||||
void forgetAction(int i) => setState(() => archive?.removeAt(i));
|
||||
|
||||
void forgetAllAction() async {
|
||||
final archive = this.archive;
|
||||
if (archive == null) return;
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
message: L10n.of(context).clearArchive,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
message: L10n.of(context)!.clearArchive,
|
||||
) !=
|
||||
OkCancelResult.ok) {
|
||||
return;
|
||||
@ -47,7 +52,7 @@ class ArchiveController extends State<Archive> {
|
||||
}
|
||||
},
|
||||
);
|
||||
setState(() => null);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1,3 +1,5 @@
|
||||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@ -9,23 +11,22 @@ import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
||||
class ArchiveView extends StatelessWidget {
|
||||
final ArchiveController controller;
|
||||
|
||||
const ArchiveView(this.controller, {Key key}) : super(key: key);
|
||||
const ArchiveView(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var archive = controller.archive;
|
||||
return FutureBuilder<List<Room>>(
|
||||
future: controller.getArchive(context),
|
||||
builder: (BuildContext context, snapshot) => Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const BackButton(),
|
||||
title: Text(L10n.of(context).archive),
|
||||
title: Text(L10n.of(context)!.archive),
|
||||
actions: [
|
||||
if (snapshot.hasData &&
|
||||
controller.archive != null &&
|
||||
controller.archive.isNotEmpty)
|
||||
if (snapshot.hasData && archive != null && archive!.isNotEmpty)
|
||||
TextButton(
|
||||
onPressed: controller.forgetAllAction,
|
||||
child: Text(L10n.of(context).clearArchive),
|
||||
child: Text(L10n.of(context)!.clearArchive),
|
||||
)
|
||||
],
|
||||
),
|
||||
@ -34,7 +35,7 @@ class ArchiveView extends StatelessWidget {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
L10n.of(context).oopsSomethingWentWrong,
|
||||
L10n.of(context)!.oopsSomethingWentWrong,
|
||||
textAlign: TextAlign.center,
|
||||
));
|
||||
}
|
||||
@ -42,15 +43,15 @@ class ArchiveView extends StatelessWidget {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2));
|
||||
} else {
|
||||
controller.archive = snapshot.data;
|
||||
if (controller.archive.isEmpty) {
|
||||
archive = snapshot.data;
|
||||
if (archive == null || archive!.isEmpty) {
|
||||
return const Center(
|
||||
child: Icon(Icons.archive_outlined, size: 80));
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: controller.archive.length,
|
||||
itemCount: archive!.length,
|
||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||
controller.archive[i],
|
||||
archive![i],
|
||||
onForget: controller.forgetAction,
|
||||
),
|
||||
);
|
||||
|
@ -1,3 +1,5 @@
|
||||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@ -13,35 +15,35 @@ import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class ChatAppBarTitle extends StatelessWidget {
|
||||
final ChatController controller;
|
||||
const ChatAppBarTitle(this.controller, {Key key}) : super(key: key);
|
||||
const ChatAppBarTitle(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (controller.selectedEvents.isNotEmpty) {
|
||||
return Text(controller.selectedEvents.length.toString());
|
||||
}
|
||||
final directChatMatrixID = controller.room.directChatMatrixID;
|
||||
return ListTile(
|
||||
leading: Avatar(
|
||||
mxContent: controller.room.avatar,
|
||||
name: controller.room.displayname,
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
onTap: controller.room.isDirectChat
|
||||
onTap: directChatMatrixID != null
|
||||
? () => showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (c) => UserBottomSheet(
|
||||
user: controller.room
|
||||
.getUserByMXIDSync(controller.room.directChatMatrixID),
|
||||
user: controller.room.getUserByMXIDSync(directChatMatrixID),
|
||||
outerContext: context,
|
||||
onMention: () => controller.sendController.text +=
|
||||
'${controller.room.getUserByMXIDSync(controller.room.directChatMatrixID).mention} ',
|
||||
'${controller.room.getUserByMXIDSync(directChatMatrixID).mention} ',
|
||||
),
|
||||
)
|
||||
: () => VRouter.of(context)
|
||||
.toSegments(['rooms', controller.room.id, 'details']),
|
||||
title: Text(
|
||||
controller.room
|
||||
.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
|
||||
.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)),
|
||||
maxLines: 1),
|
||||
subtitle: StreamBuilder<Object>(
|
||||
stream: Matrix.of(context)
|
||||
|
@ -1,3 +1,5 @@
|
||||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
@ -6,7 +8,7 @@ import 'chat.dart';
|
||||
|
||||
class ChatEmojiPicker extends StatelessWidget {
|
||||
final ChatController controller;
|
||||
const ChatEmojiPicker(this.controller, {Key key}) : super(key: key);
|
||||
const ChatEmojiPicker(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
//@dart=2.12
|
||||
// This file is auto-generated using scripts/generate_command_hints_glue.sh.
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
Loading…
Reference in New Issue
Block a user