mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 03:42:13 +00:00
rewrite global user variable
This commit is contained in:
parent
3d35615136
commit
56aa6e9f7e
5 changed files with 71 additions and 85 deletions
|
|
@ -176,12 +176,12 @@ class _AppMainWidgetState extends State<AppMainWidget> {
|
||||||
_isTwonlyLocked = false;
|
_isTwonlyLocked = false;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else if (AppSession.currentUser.twonlySafeBackup == null && !_skipBackup) {
|
} else if (AppSession.currentUser.twonlySafeBackup == null &&
|
||||||
|
!_skipBackup) {
|
||||||
child = SetupBackupView(
|
child = SetupBackupView(
|
||||||
callBack: () {
|
callBack: () => setState(() {
|
||||||
_skipBackup = true;
|
_skipBackup = true;
|
||||||
setState(() {});
|
}),
|
||||||
},
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
child = HomeView(
|
child = HomeView(
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,9 @@ class AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppGlobalKeys {
|
class AppGlobalKeys {
|
||||||
static final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
|
static final scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||||
GlobalKey<ScaffoldMessengerState>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
late ApiService apiService;
|
|
||||||
|
|
||||||
// uses for background notification
|
|
||||||
late TwonlyDB twonlyDB;
|
|
||||||
|
|
||||||
// Cached UserData in the memory. Every time the user data is changed the `updateUserdata` function is called,
|
|
||||||
// which will update this global variable. The variable is set in the main.dart and after the user has registered in the register.view.dart
|
|
||||||
class AppSession {
|
class AppSession {
|
||||||
static late UserData currentUser;
|
static late UserData currentUser;
|
||||||
|
|
||||||
|
|
@ -48,3 +40,6 @@ class AppSession {
|
||||||
_userDataUpdateController.add(null);
|
_userDataUpdateController.add(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
late ApiService apiService;
|
||||||
|
late TwonlyDB twonlyDB;
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@ class SettingsChangeProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
await updateUserdata((user) {
|
await updateUser((u) => u.themeMode = newThemeMode);
|
||||||
user.themeMode = newThemeMode;
|
|
||||||
return user;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ class _PublicProfileViewState extends State<PublicProfileView> {
|
||||||
_qrCode = await getProfileQrCodeData();
|
_qrCode = await getProfileQrCodeData();
|
||||||
_userAvatar = await getUserAvatar();
|
_userAvatar = await getUserAvatar();
|
||||||
_publicKey = await getUserPublicKey();
|
_publicKey = await getUserPublicKey();
|
||||||
|
if (mounted) setState(() {});
|
||||||
setState(() {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -126,7 +125,9 @@ class _PublicProfileViewState extends State<PublicProfileView> {
|
||||||
text: context.lang.shareYourProfile,
|
text: context.lang.shareYourProfile,
|
||||||
subtitle: (_publicKey == null)
|
subtitle: (_publicKey == null)
|
||||||
? null
|
? null
|
||||||
: Text('https://me.twonly.eu/${AppSession.currentUser.username}'),
|
: Text(
|
||||||
|
'https://me.twonly.eu/${AppSession.currentUser.username}',
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final params = ShareParams(
|
final params = ShareParams(
|
||||||
text:
|
text:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:twonly/globals.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
import 'package:twonly/src/utils/storage.dart';
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
import 'package:twonly/src/views/components/animate_icon.dart';
|
import 'package:twonly/src/views/components/animate_icon.dart';
|
||||||
|
|
@ -14,32 +13,30 @@ class ChatReactionSelectionView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ChatReactionSelectionView extends State<ChatReactionSelectionView> {
|
class _ChatReactionSelectionView extends State<ChatReactionSelectionView> {
|
||||||
List<String> selectedEmojis = [];
|
List<String> _selectedEmojis = [];
|
||||||
|
|
||||||
|
List<String> _emojisFromSession() {
|
||||||
|
final user = AppSession.currentUser;
|
||||||
|
if (user.preSelectedEmojies != null) {
|
||||||
|
return user.preSelectedEmojies!;
|
||||||
|
}
|
||||||
|
return EmojiAnimation.animatedIcons.keys.toList().sublist(0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
unawaited(initAsync());
|
_selectedEmojis = _emojisFromSession();
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> initAsync() async {
|
|
||||||
final user = await getUser();
|
|
||||||
if (user != null && user.preSelectedEmojies != null) {
|
|
||||||
selectedEmojis = user.preSelectedEmojies!;
|
|
||||||
} else {
|
|
||||||
selectedEmojis = EmojiAnimation.animatedIcons.keys.toList().sublist(0, 6);
|
|
||||||
}
|
|
||||||
setState(() {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onEmojiSelected(String emoji) async {
|
Future<void> _onEmojiSelected(String emoji) async {
|
||||||
if (selectedEmojis.contains(emoji)) {
|
if (_selectedEmojis.contains(emoji)) {
|
||||||
selectedEmojis.remove(emoji);
|
_selectedEmojis.remove(emoji);
|
||||||
} else {
|
} else {
|
||||||
if (selectedEmojis.length < 12) {
|
if (_selectedEmojis.length < 12) {
|
||||||
selectedEmojis.add(emoji);
|
_selectedEmojis.add(emoji);
|
||||||
await updateUser((user) {
|
await updateUser((user) {
|
||||||
user.preSelectedEmojies = selectedEmojis;
|
user.preSelectedEmojies = _selectedEmojis;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
|
@ -55,56 +52,52 @@ class _ChatReactionSelectionView extends State<ChatReactionSelectionView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return StreamBuilder<void>(
|
||||||
appBar: AppBar(
|
stream: AppSession.onUserUpdated,
|
||||||
title: const Text('Select Reactions'),
|
builder: (context, _) {
|
||||||
),
|
_selectedEmojis = _emojisFromSession();
|
||||||
body: GridView.builder(
|
return Scaffold(
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
appBar: AppBar(
|
||||||
crossAxisCount: 4, // Number of columns
|
title: const Text('Select Reactions'),
|
||||||
),
|
),
|
||||||
itemCount: EmojiAnimation.animatedIcons.keys.length,
|
body: GridView.builder(
|
||||||
itemBuilder: (context, index) {
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
final emoji = EmojiAnimation.animatedIcons.keys.elementAt(index);
|
crossAxisCount: 4,
|
||||||
return GestureDetector(
|
),
|
||||||
onTap: () async {
|
itemCount: EmojiAnimation.animatedIcons.keys.length,
|
||||||
await _onEmojiSelected(emoji);
|
itemBuilder: (context, index) {
|
||||||
},
|
final emoji = EmojiAnimation.animatedIcons.keys.elementAt(index);
|
||||||
child: Card(
|
return GestureDetector(
|
||||||
color: selectedEmojis.contains(emoji)
|
onTap: () => _onEmojiSelected(emoji),
|
||||||
? context.color.primary.withAlpha(150)
|
child: Card(
|
||||||
: context.color.surface,
|
color: _selectedEmojis.contains(emoji)
|
||||||
child: Center(
|
? context.color.primary.withAlpha(150)
|
||||||
child: SizedBox(
|
: context.color.surface,
|
||||||
width: 40,
|
child: Center(
|
||||||
height: 40,
|
child: SizedBox(
|
||||||
child: EmojiAnimation(
|
width: 40,
|
||||||
emoji: emoji,
|
height: 40,
|
||||||
// repeat: selectedEmojis.contains(emoji),
|
child: EmojiAnimation(emoji: emoji),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
floatingActionButton: Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 30),
|
||||||
|
child: FloatingActionButton(
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
onPressed: () => updateUser(
|
||||||
|
(u) => u.preSelectedEmojies = EmojiAnimation.animatedIcons.keys
|
||||||
|
.toList()
|
||||||
|
.sublist(0, 6),
|
||||||
),
|
),
|
||||||
|
child: const Icon(Icons.settings_backup_restore_rounded),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
);
|
||||||
),
|
},
|
||||||
floatingActionButton: Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 30),
|
|
||||||
child: FloatingActionButton(
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
onPressed: () async {
|
|
||||||
selectedEmojis = EmojiAnimation.animatedIcons.keys.toList().sublist(
|
|
||||||
0,
|
|
||||||
6,
|
|
||||||
);
|
|
||||||
setState(() {});
|
|
||||||
await updateUser((user) {
|
|
||||||
user.preSelectedEmojies = selectedEmojis;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Icon(Icons.settings_backup_restore_rounded),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue