fluffychat/lib/utils/platform_infos.dart

64 lines
2.1 KiB
Dart
Raw Normal View History

2020-09-26 18:27:15 +00:00
import 'dart:io';
2021-04-09 14:15:03 +00:00
import 'package:fluffychat/views/widgets/sentry_switch_list_tile.dart';
2020-09-26 18:27:15 +00:00
import 'package:flutter/foundation.dart';
2021-01-17 14:43:38 +00:00
import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-04-09 14:29:48 +00:00
import '../config/app_config.dart';
2020-09-26 18:27:15 +00:00
abstract class PlatformInfos {
static bool get isWeb => kIsWeb;
2021-02-07 16:18:38 +00:00
static bool get isLinux => !kIsWeb && Platform.isLinux;
static bool get isWindows => !kIsWeb && Platform.isWindows;
static bool get isMacOS => !kIsWeb && Platform.isMacOS;
static bool get isIOS => !kIsWeb && Platform.isIOS;
static bool get isAndroid => !kIsWeb && Platform.isAndroid;
2020-10-04 14:11:18 +00:00
2021-02-07 16:18:38 +00:00
static bool get isCupertinoStyle => isIOS || isMacOS;
2020-11-22 21:48:10 +00:00
2021-02-07 16:18:38 +00:00
static bool get isMobile => isAndroid || isIOS;
2020-10-04 14:11:18 +00:00
/// For desktops which don't support ChachedNetworkImage yet
2021-02-07 16:18:38 +00:00
static bool get isBetaDesktop => isWindows || isLinux;
2020-10-04 14:11:18 +00:00
2021-02-07 16:18:38 +00:00
static bool get isDesktop => isLinux || isWindows || isMacOS;
2020-10-28 07:05:10 +00:00
2020-09-26 18:27:15 +00:00
static bool get usesTouchscreen => !isMobile;
2021-01-17 14:43:38 +00:00
2021-02-07 16:18:38 +00:00
static String get clientName =>
2021-04-09 14:54:00 +00:00
'${AppConfig.applicationName} ${isWeb ? 'web' : Platform.operatingSystem}';
2021-02-07 16:18:38 +00:00
2021-01-17 14:43:38 +00:00
static Future<String> getVersion() async {
var version = kIsWeb ? 'Web' : 'Unknown';
try {
version = (await PackageInfo.fromPlatform()).version;
} catch (_) {}
return version;
}
static void showDialog(BuildContext context) async {
2021-04-14 08:37:15 +00:00
final version = await PlatformInfos.getVersion();
2021-01-17 14:43:38 +00:00
showAboutDialog(
context: context,
2021-02-24 11:17:23 +00:00
useRootNavigator: false,
2021-01-17 14:43:38 +00:00
children: [
Text('Version: $version'),
2021-03-04 11:28:06 +00:00
OutlinedButton(
2021-01-17 14:43:38 +00:00
onPressed: () => launch(AppConfig.sourceCodeUrl),
2021-03-04 11:28:06 +00:00
child: Text(L10n.of(context).sourceCode),
2021-01-17 14:43:38 +00:00
),
2021-03-04 11:28:06 +00:00
OutlinedButton(
2021-01-20 18:53:19 +00:00
onPressed: () => launch(AppConfig.emojiFontUrl),
2021-03-04 11:28:06 +00:00
child: Text(AppConfig.emojiFontName),
2021-01-17 14:43:38 +00:00
),
2021-01-22 20:39:37 +00:00
SentrySwitchListTile(label: L10n.of(context).sendBugReports),
2021-01-17 14:43:38 +00:00
],
2021-01-22 20:39:37 +00:00
applicationIcon: Image.asset('assets/logo.png', width: 64, height: 64),
2021-01-17 14:43:38 +00:00
applicationName: AppConfig.applicationName,
);
}
2020-09-26 18:27:15 +00:00
}