mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-24 04:59:26 +01:00
Merge branch 'krille/fluffychat-model' into 'main'
refactor: Use Provider See merge request famedly/fluffychat!337
This commit is contained in:
commit
55cca75002
@ -15,6 +15,7 @@ import 'package:flushbar/flushbar.dart';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
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';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:universal_html/prefer_universal/html.dart' as html;
|
import 'package:universal_html/prefer_universal/html.dart' as html;
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
@ -43,12 +44,8 @@ class Matrix extends StatefulWidget {
|
|||||||
MatrixState createState() => MatrixState();
|
MatrixState createState() => MatrixState();
|
||||||
|
|
||||||
/// Returns the (nearest) Client instance of your application.
|
/// Returns the (nearest) Client instance of your application.
|
||||||
static MatrixState of(BuildContext context) {
|
static MatrixState of(BuildContext context) =>
|
||||||
var newState =
|
Provider.of<MatrixState>(context, listen: false);
|
||||||
(context.dependOnInheritedWidgetOfExactType<_InheritedMatrix>()).data;
|
|
||||||
newState.context = FirebaseController.context = context;
|
|
||||||
return newState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MatrixState extends State<Matrix> {
|
class MatrixState extends State<Matrix> {
|
||||||
@ -57,8 +54,6 @@ class MatrixState extends State<Matrix> {
|
|||||||
@override
|
@override
|
||||||
BuildContext context;
|
BuildContext context;
|
||||||
|
|
||||||
static const String userStatusesType = 'chat.fluffy.user_statuses';
|
|
||||||
|
|
||||||
Map<String, dynamic> get shareContent => _shareContent;
|
Map<String, dynamic> get shareContent => _shareContent;
|
||||||
set shareContent(Map<String, dynamic> content) {
|
set shareContent(Map<String, dynamic> content) {
|
||||||
_shareContent = content;
|
_shareContent = content;
|
||||||
@ -438,26 +433,9 @@ class MatrixState extends State<Matrix> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return _InheritedMatrix(
|
return Provider(
|
||||||
data: this,
|
create: (_) => this,
|
||||||
child: widget.child,
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -300,16 +300,11 @@ class _ChatListState extends State<ChatList> {
|
|||||||
ConnectionStatusHeader(),
|
ConnectionStatusHeader(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: StreamBuilder(
|
child: StreamBuilder(
|
||||||
stream:
|
stream: Matrix.of(context)
|
||||||
Matrix.of(context).client.onSync.stream.where(
|
.client
|
||||||
(s) =>
|
.onSync
|
||||||
s.hasRoomUpdate ||
|
.stream
|
||||||
s.accountData
|
.where((s) => s.hasRoomUpdate),
|
||||||
.where((a) =>
|
|
||||||
a.type ==
|
|
||||||
MatrixState.userStatusesType)
|
|
||||||
.isNotEmpty,
|
|
||||||
),
|
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return FutureBuilder<void>(
|
return FutureBuilder<void>(
|
||||||
future: waitForFirstSync(context),
|
future: waitForFirstSync(context),
|
||||||
|
Loading…
Reference in New Issue
Block a user