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

View File

@ -19,6 +19,13 @@ class NotificationProvider extends ChangeNotifier {
_sn = context.read<SnNetworkProvider>();
_ua = context.read<UserProvider>();
_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 {

View File

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

View File

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

View File

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

View File

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