Push token push (to server)

This commit is contained in:
LittleSheep 2024-11-21 22:55:00 +08:00
parent d41e358c6a
commit 7e63611416
6 changed files with 37 additions and 14 deletions

View File

@ -74,8 +74,8 @@ class SolianApp extends StatelessWidget {
Provider(create: (ctx) => SnAttachmentProvider(ctx)), Provider(create: (ctx) => SnAttachmentProvider(ctx)),
Provider(create: (ctx) => UserDirectoryProvider(ctx)), Provider(create: (ctx) => UserDirectoryProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => UserProvider(ctx)), ChangeNotifierProvider(create: (ctx) => UserProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => NotificationProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => WebSocketProvider(ctx)), ChangeNotifierProvider(create: (ctx) => WebSocketProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => NotificationProvider(ctx)),
ChangeNotifierProvider(create: (ctx) => ChatChannelProvider(ctx)), ChangeNotifierProvider(create: (ctx) => ChatChannelProvider(ctx)),
], ],
child: AppMainContent(), child: AppMainContent(),
@ -98,6 +98,7 @@ class AppMainContent extends StatelessWidget {
context.read<NavigationProvider>(); context.read<NavigationProvider>();
context.read<WebSocketProvider>(); context.read<WebSocketProvider>();
context.read<ChatChannelProvider>(); context.read<ChatChannelProvider>();
context.read<NotificationProvider>();
final th = context.watch<ThemeProvider>(); final th = context.watch<ThemeProvider>();

View File

@ -19,6 +19,13 @@ class NotificationProvider extends ChangeNotifier {
_sn = context.read<SnNetworkProvider>(); _sn = context.read<SnNetworkProvider>();
_ua = context.read<UserProvider>(); _ua = context.read<UserProvider>();
_ws = context.read<WebSocketProvider>(); _ws = context.read<WebSocketProvider>();
// Delay to wait user provider ready to use
Future.delayed(const Duration(milliseconds: 3000), () async {
if (!_ua.isAuthorized) return;
log("Registering push notifications...");
await registerPushNotifications();
});
} }
Future<void> registerPushNotifications() async { Future<void> registerPushNotifications() async {

View File

@ -1,4 +1,5 @@
import 'package:animations/animations.dart'; import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:surface/screens/account.dart'; import 'package:surface/screens/account.dart';
import 'package:surface/screens/account/profile_edit.dart'; import 'package:surface/screens/account/profile_edit.dart';
@ -64,6 +65,7 @@ final _appRoutes = [
return FadeThroughTransition( return FadeThroughTransition(
animation: animation, animation: animation,
secondaryAnimation: secondaryAnimation, secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: AppBackground(isLessOptimization: true, child: child), child: AppBackground(isLessOptimization: true, child: child),
); );
}, },
@ -82,6 +84,7 @@ final _appRoutes = [
return FadeThroughTransition( return FadeThroughTransition(
animation: animation, animation: animation,
secondaryAnimation: secondaryAnimation, secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: AppBackground(isLessOptimization: true, child: child), child: AppBackground(isLessOptimization: true, child: child),
); );
}, },
@ -124,6 +127,7 @@ final _appRoutes = [
return FadeThroughTransition( return FadeThroughTransition(
animation: animation, animation: animation,
secondaryAnimation: secondaryAnimation, secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: AppBackground( child: AppBackground(
isLessOptimization: true, isLessOptimization: true,
child: child, child: child,
@ -153,6 +157,7 @@ final _appRoutes = [
return FadeThroughTransition( return FadeThroughTransition(
animation: animation, animation: animation,
secondaryAnimation: secondaryAnimation, secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: AppBackground( child: AppBackground(
isLessOptimization: true, isLessOptimization: true,
child: child, child: child,

View File

@ -109,13 +109,11 @@ class _PostDetailScreenState extends State<PostDetailScreen> {
), ),
if (_data != null) if (_data != null)
SliverToBoxAdapter( SliverToBoxAdapter(
child: Container(
constraints: const BoxConstraints(maxWidth: 640),
child: PostItem( child: PostItem(
data: _data!, data: _data!,
maxWidth: 640,
showComments: false, showComments: false,
), ),
).center(),
), ),
const SliverToBoxAdapter(child: Divider(height: 1)), const SliverToBoxAdapter(child: Divider(height: 1)),
if (_data != null) if (_data != null)

View File

@ -3,14 +3,17 @@ import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:responsive_framework/responsive_framework.dart';
class AppBackground extends StatelessWidget { class AppBackground extends StatelessWidget {
final Widget child; final Widget child;
final bool isLessOptimization; final bool isLessOptimization;
final bool isRoot;
const AppBackground({ const AppBackground({
super.key, super.key,
required this.child, required this.child,
this.isLessOptimization = false, this.isLessOptimization = false,
this.isRoot = false,
}); });
Widget _buildWithBackgroundImage( Widget _buildWithBackgroundImage(
@ -77,6 +80,8 @@ class AppBackground extends StatelessWidget {
future: future:
kIsWeb ? Future.value(null) : getApplicationDocumentsDirectory(), kIsWeb ? Future.value(null) : getApplicationDocumentsDirectory(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (isRoot ||
ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE)) {
if (snapshot.hasData) { if (snapshot.hasData) {
final path = '${snapshot.data!.path}/app_background_image'; final path = '${snapshot.data!.path}/app_background_image';
final file = File(path); final file = File(path);
@ -84,9 +89,15 @@ class AppBackground extends StatelessWidget {
return _buildWithBackgroundImage(context, file, child); return _buildWithBackgroundImage(context, file, child);
} }
} }
}
final backgroundColor =
ResponsiveBreakpoints.of(context).largerThan(MOBILE)
? Colors.transparent
: Theme.of(context).colorScheme.surface;
return Material( return Material(
color: Theme.of(context).colorScheme.surface, color: backgroundColor,
child: child, child: child,
); );
}, },

View File

@ -88,6 +88,7 @@ class AppRootScaffold extends StatelessWidget {
); );
return AppBackground( return AppBackground(
isRoot: true,
child: Scaffold( child: Scaffold(
body: Column( body: Column(
children: [ children: [