Merge branch 'krille/fluffychat-model' into 'main'

refactor: Use Provider

See merge request famedly/fluffychat!337
This commit is contained in:
Krille Fear 2021-01-15 19:20:33 +00:00
commit 55cca75002
2 changed files with 10 additions and 37 deletions

View File

@ -15,6 +15,7 @@ import 'package:flushbar/flushbar.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:provider/provider.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:url_launcher/url_launcher.dart';
import 'package:path_provider/path_provider.dart';
@ -43,12 +44,8 @@ class Matrix extends StatefulWidget {
MatrixState createState() => MatrixState();
/// Returns the (nearest) Client instance of your application.
static MatrixState of(BuildContext context) {
var newState =
(context.dependOnInheritedWidgetOfExactType<_InheritedMatrix>()).data;
newState.context = FirebaseController.context = context;
return newState;
}
static MatrixState of(BuildContext context) =>
Provider.of<MatrixState>(context, listen: false);
}
class MatrixState extends State<Matrix> {
@ -57,8 +54,6 @@ class MatrixState extends State<Matrix> {
@override
BuildContext context;
static const String userStatusesType = 'chat.fluffy.user_statuses';
Map<String, dynamic> get shareContent => _shareContent;
set shareContent(Map<String, dynamic> content) {
_shareContent = content;
@ -438,26 +433,9 @@ class MatrixState extends State<Matrix> {
@override
Widget build(BuildContext context) {
return _InheritedMatrix(
data: this,
return Provider(
create: (_) => this,
child: widget.child,
);
}
}
class _InheritedMatrix extends InheritedWidget {
final MatrixState data;
_InheritedMatrix({Key key, this.data, Widget child})
: super(key: key, child: child);
@override
bool updateShouldNotify(_InheritedMatrix old) {
var update = old.data.client.accessToken != data.client.accessToken ||
old.data.client.userID != data.client.userID ||
old.data.client.deviceID != data.client.deviceID ||
old.data.client.deviceName != data.client.deviceName ||
old.data.client.homeserver != data.client.homeserver;
return update;
}
}

View File

@ -300,16 +300,11 @@ class _ChatListState extends State<ChatList> {
ConnectionStatusHeader(),
Expanded(
child: StreamBuilder(
stream:
Matrix.of(context).client.onSync.stream.where(
(s) =>
s.hasRoomUpdate ||
s.accountData
.where((a) =>
a.type ==
MatrixState.userStatusesType)
.isNotEmpty,
),
stream: Matrix.of(context)
.client
.onSync
.stream
.where((s) => s.hasRoomUpdate),
builder: (context, snapshot) {
return FutureBuilder<void>(
future: waitForFirstSync(context),