fluffychat/lib/utils/platform_infos.dart

56 lines
1.6 KiB
Dart
Raw Permalink Normal View History

2020-09-26 20:27:15 +02:00
import 'dart:io';
import 'package:flutter/foundation.dart';
2021-01-17 15:43:38 +01: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';
import '../app_config.dart';
2020-09-26 20:27:15 +02:00
abstract class PlatformInfos {
static bool get isWeb => kIsWeb;
2020-10-04 16:11:18 +02:00
2020-11-22 22:48:10 +01:00
static bool get isCupertinoStyle =>
!kIsWeb && (Platform.isIOS || Platform.isMacOS);
2020-09-26 20:27:15 +02:00
static bool get isMobile => !kIsWeb && (Platform.isAndroid || Platform.isIOS);
2020-10-04 16:11:18 +02:00
/// For desktops which don't support ChachedNetworkImage yet
static bool get isBetaDesktop =>
!kIsWeb && (Platform.isWindows || Platform.isLinux);
2020-10-28 08:05:10 +01:00
static bool get isDesktop =>
!kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS);
2020-09-26 20:27:15 +02:00
static bool get usesTouchscreen => !isMobile;
2021-01-17 15:43:38 +01: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 {
var version = await PlatformInfos.getVersion();
showAboutDialog(
context: context,
children: [
Text('Version: $version'),
RaisedButton(
child: Text(L10n.of(context).sourceCode),
onPressed: () => launch(AppConfig.sourceCodeUrl),
),
RaisedButton(
child: Text(L10n.of(context).help),
onPressed: () => launch(AppConfig.supportUrl),
),
],
applicationIcon: Image.asset('assets/logo.png', width: 100, height: 100),
applicationName: AppConfig.applicationName,
);
}
2020-09-26 20:27:15 +02:00
}