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