🐛 Trying to fix push notification
This commit is contained in:
parent
2ea9f5e907
commit
9dd6cffe0c
@ -1,24 +1,33 @@
|
|||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:island/pods/network.dart';
|
||||||
|
import 'package:island/services/notify.dart';
|
||||||
|
import 'package:island/services/udid.native.dart';
|
||||||
|
import 'package:island/widgets/alert.dart';
|
||||||
|
import 'package:material_symbols_icons/symbols.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:styled_widget/styled_widget.dart';
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
class AboutScreen extends StatefulWidget {
|
class AboutScreen extends ConsumerStatefulWidget {
|
||||||
const AboutScreen({super.key});
|
const AboutScreen({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AboutScreen> createState() => _AboutScreenState();
|
ConsumerState<AboutScreen> createState() => _AboutScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AboutScreenState extends State<AboutScreen> {
|
class _AboutScreenState extends ConsumerState<AboutScreen> {
|
||||||
PackageInfo _packageInfo = PackageInfo(
|
PackageInfo _packageInfo = PackageInfo(
|
||||||
appName: 'Solian',
|
appName: 'Solian',
|
||||||
packageName: 'dev.solsynth.solian',
|
packageName: 'dev.solsynth.solian',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
buildNumber: '1',
|
buildNumber: '1',
|
||||||
);
|
);
|
||||||
|
BaseDeviceInfo? _deviceInfo;
|
||||||
|
String? _deviceUdid;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
String? _errorMessage;
|
String? _errorMessage;
|
||||||
|
|
||||||
@ -26,6 +35,7 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_initPackageInfo();
|
_initPackageInfo();
|
||||||
|
_initDeviceInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initPackageInfo() async {
|
Future<void> _initPackageInfo() async {
|
||||||
@ -49,6 +59,25 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _initDeviceInfo() async {
|
||||||
|
try {
|
||||||
|
final deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
|
_deviceInfo = await deviceInfoPlugin.deviceInfo;
|
||||||
|
_deviceUdid = await getUdid();
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_errorMessage = 'aboutScreenFailedToLoadDeviceInfo'.tr(
|
||||||
|
args: [e.toString()],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _launchURL(String url) async {
|
Future<void> _launchURL(String url) async {
|
||||||
final uri = Uri.parse(url);
|
final uri = Uri.parse(url);
|
||||||
if (await canLaunchUrl(uri)) {
|
if (await canLaunchUrl(uri)) {
|
||||||
@ -127,6 +156,47 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
if (_deviceInfo != null) const SizedBox(height: 16),
|
||||||
|
|
||||||
|
if (_deviceInfo != null)
|
||||||
|
_buildSection(
|
||||||
|
context,
|
||||||
|
title: 'Device Information',
|
||||||
|
children: [
|
||||||
|
_buildInfoItem(
|
||||||
|
context,
|
||||||
|
icon: Symbols.label,
|
||||||
|
label: 'Device Name',
|
||||||
|
value: _deviceInfo?.data['name'],
|
||||||
|
),
|
||||||
|
_buildInfoItem(
|
||||||
|
context,
|
||||||
|
icon: Symbols.fingerprint,
|
||||||
|
label: 'Device Identifier',
|
||||||
|
value: _deviceUdid ?? 'N/A',
|
||||||
|
copyable: true,
|
||||||
|
),
|
||||||
|
const Divider(height: 1),
|
||||||
|
_buildListTile(
|
||||||
|
context,
|
||||||
|
icon: Symbols.notifications_active,
|
||||||
|
title: 'Reactivate Push Notifications',
|
||||||
|
onTap: () async {
|
||||||
|
showLoadingModal(context);
|
||||||
|
try {
|
||||||
|
await subscribePushNotification(
|
||||||
|
ref.watch(apiClientProvider),
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
showErrorAlert(err);
|
||||||
|
} finally {
|
||||||
|
if (context.mounted) hideLoadingModal(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
// Links Card
|
// Links Card
|
||||||
@ -247,6 +317,7 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||||||
required IconData icon,
|
required IconData icon,
|
||||||
required String label,
|
required String label,
|
||||||
required String value,
|
required String value,
|
||||||
|
bool copyable = false,
|
||||||
}) {
|
}) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
@ -263,11 +334,12 @@ class _AboutScreenState extends State<AboutScreen> {
|
|||||||
SelectableText(
|
SelectableText(
|
||||||
value,
|
value,
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
maxLines: copyable ? 1 : null,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (value.startsWith('http') || value.contains('@'))
|
if (value.startsWith('http') || value.contains('@') || copyable)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.copy, size: 16),
|
icon: const Icon(Icons.copy, size: 16),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
@ -63,7 +63,10 @@ StreamSubscription<WebSocketPacket> setupNotificationListener(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> subscribePushNotification(Dio apiClient) async {
|
Future<void> subscribePushNotification(
|
||||||
|
Dio apiClient, {
|
||||||
|
bool detailedErrors = false,
|
||||||
|
}) async {
|
||||||
await FirebaseMessaging.instance.requestPermission(
|
await FirebaseMessaging.instance.requestPermission(
|
||||||
provisional: true,
|
provisional: true,
|
||||||
alert: true,
|
alert: true,
|
||||||
@ -97,6 +100,8 @@ Future<void> subscribePushNotification(Dio apiClient) async {
|
|||||||
deviceToken,
|
deviceToken,
|
||||||
!kIsWeb && (Platform.isIOS || Platform.isMacOS) ? 0 : 1,
|
!kIsWeb && (Platform.isIOS || Platform.isMacOS) ? 0 : 1,
|
||||||
);
|
);
|
||||||
|
} else if (detailedErrors) {
|
||||||
|
throw Exception("Failed to get device token for push notifications.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user