WallPaper_FSX_Flutter/lib/modules/settings/settings_controller.dart
fengshengxiong 9f361ce560 1.集成firebase
2.优化功能
2024-05-23 18:22:18 +08:00

50 lines
1.6 KiB
Dart

import 'dart:io';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:hello_wallpaper/common/utils/local_path_util.dart';
import 'package:hello_wallpaper/generated/assets.dart';
import 'package:hello_wallpaper/res/values/strings.dart';
import 'package:hello_wallpaper/routes/app_pages.dart';
import 'package:share_plus/share_plus.dart';
class SettingsController extends GetxController {
// final options = ['About', 'Feedback', 'Share', 'Privacy Policy', 'Terms of Service'];
final options = ['About', 'Share', 'Privacy Policy', 'Terms of Service'];
void onTapItem(int index) async {
if (index == 0) {
Get.toNamed(AppPages.about);
}
if (index == 1) {
Share.shareXFiles(
[await getImageFileFromAssets(Assets.iconIconApp)],
text: appName,
);
}
if (index == 2) {
Get.toNamed(AppPages.webPage, arguments: {
'title': options[index],
'url': 'https://nowwallpaperapp.mystrikingly.com/privacy',
});
}
if (index == 3) {
Get.toNamed(AppPages.webPage, arguments: {
'title': options[index],
'url': 'https://nowwallpaperapp.mystrikingly.com/terms'
});
}
}
Future<XFile> getImageFileFromAssets(String path) async {
final byteData = await rootBundle.load(path);
final file = File('${(await LocalPathUtil.getTemporaryPath()).path}/$path');
await file.create(recursive: true);
await file.writeAsBytes(byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return XFile(file.path);
}
}