集成Applovin Max广告
This commit is contained in:
parent
17446a664c
commit
d0031ddce7
@ -50,7 +50,7 @@ android {
|
|||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||||
// minSdkVersion flutter.minSdkVersion
|
// minSdkVersion flutter.minSdkVersion
|
||||||
minSdkVersion 24
|
minSdkVersion 19
|
||||||
targetSdkVersion flutter.targetSdkVersion
|
targetSdkVersion flutter.targetSdkVersion
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|||||||
134
lib/applovin_max/applovin_manage.dart
Normal file
134
lib/applovin_max/applovin_manage.dart
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
// Author: fengshengxiong
|
||||||
|
// Date: 2024/5/20
|
||||||
|
// Description: 广告管理
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:applovin_max/applovin_max.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:now_wallpaper/common/utils/log_print.dart';
|
||||||
|
|
||||||
|
class ApplovinManage {
|
||||||
|
ApplovinManage._();
|
||||||
|
|
||||||
|
static final ApplovinManage _instance = ApplovinManage._();
|
||||||
|
|
||||||
|
factory ApplovinManage() => _instance;
|
||||||
|
|
||||||
|
/// sdkKey
|
||||||
|
final String applovinKey = 'nEo4OHOhAZuAK9-IARuNaUfW-yDLBayq9FIGZs0L9XMNTByuDV6dsvMEIGnEAkQu-KR8D42QdKRlbniP910xnK';
|
||||||
|
|
||||||
|
/// 广告单元Id
|
||||||
|
final String adUnitId1 = 'edc4bd530e79af75';
|
||||||
|
final String adUnitId2 = '3f38d70ff5e85f92';
|
||||||
|
final String adUnitId3 = '8a0fc2feeba310bc';
|
||||||
|
|
||||||
|
/// 是否已初始化
|
||||||
|
bool isInitialized = false;
|
||||||
|
|
||||||
|
/// 是否是启动屏幕
|
||||||
|
bool isSplashScreen = true;
|
||||||
|
|
||||||
|
/// 重试计数
|
||||||
|
final _maxExponentialRetryCount = 6;
|
||||||
|
var _interstitialRetryAttempt = 0;
|
||||||
|
|
||||||
|
/// 倒计时30秒,3个广告单元不重复展示
|
||||||
|
// Timer? _timer;
|
||||||
|
// int _timeCount = 30;
|
||||||
|
|
||||||
|
/// 初始化
|
||||||
|
Future<void> initApplovin() async {
|
||||||
|
MaxConfiguration? configuration = await AppLovinMAX.initialize(applovinKey);
|
||||||
|
if (configuration != null) {
|
||||||
|
isInitialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 初始化插页广告
|
||||||
|
void initializeInterstitialAds({VoidCallback? onAdLoadedCallback}) {
|
||||||
|
if (isInitialized) {
|
||||||
|
AppLovinMAX.setInterstitialListener(InterstitialListener(
|
||||||
|
onAdLoadedCallback: (ad) {
|
||||||
|
LogPrint.d('插页广告加载成功:${ad.adUnitId}');
|
||||||
|
if (ad.adUnitId == adUnitId1 && isSplashScreen) {
|
||||||
|
isSplashScreen = false;
|
||||||
|
onAdLoadedCallback!;
|
||||||
|
showAdIfReady(adUnitId1);
|
||||||
|
// AppLovinMAX.showInterstitial(adUnitId1);
|
||||||
|
AppLovinMAX.loadInterstitial(adUnitId1);
|
||||||
|
}
|
||||||
|
_interstitialRetryAttempt = 0;
|
||||||
|
},
|
||||||
|
onAdLoadFailedCallback: (adUnitId, error) {
|
||||||
|
LogPrint.d('插页广告加载失败adUnitId:$adUnitId,code:${error.code},message:${error.message}');
|
||||||
|
if (adUnitId == adUnitId1 && isSplashScreen) {
|
||||||
|
isSplashScreen = false;
|
||||||
|
}
|
||||||
|
// Applovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds).
|
||||||
|
_interstitialRetryAttempt = _interstitialRetryAttempt + 1;
|
||||||
|
if (_interstitialRetryAttempt > _maxExponentialRetryCount) return;
|
||||||
|
int retryDelay = pow(2, min(_maxExponentialRetryCount, _interstitialRetryAttempt)).toInt();
|
||||||
|
|
||||||
|
Future.delayed(Duration(milliseconds: retryDelay * 1000), () {
|
||||||
|
AppLovinMAX.loadInterstitial(adUnitId);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onAdDisplayedCallback: (ad) {
|
||||||
|
LogPrint.d('插页广告显示成功:${ad.adUnitId}');
|
||||||
|
// _startTimer();
|
||||||
|
},
|
||||||
|
onAdDisplayFailedCallback: (ad, error) {
|
||||||
|
LogPrint.d('插页广告显示失败adUnitId:${ad.adUnitId},code:${error.code},message:${error.message}');
|
||||||
|
},
|
||||||
|
onAdClickedCallback: (ad) {},
|
||||||
|
onAdHiddenCallback: (ad) {
|
||||||
|
LogPrint.d('插页广告隐藏:${ad.adUnitId}');
|
||||||
|
AppLovinMAX.loadInterstitial(ad.adUnitId);
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
AppLovinMAX.loadInterstitial(adUnitId1);
|
||||||
|
AppLovinMAX.loadInterstitial(adUnitId2);
|
||||||
|
AppLovinMAX.loadInterstitial(adUnitId3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 显示插页广告,如果准备好
|
||||||
|
Future<void> showAdIfReady(String adUnitId) async {
|
||||||
|
if (!isInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isReady = (await AppLovinMAX.isInterstitialReady(adUnitId))!;
|
||||||
|
if (isReady) {
|
||||||
|
// if (_timeCount == 30) {
|
||||||
|
// AppLovinMAX.showInterstitial(adUnitId);
|
||||||
|
// }
|
||||||
|
AppLovinMAX.showInterstitial(adUnitId);
|
||||||
|
} else {
|
||||||
|
AppLovinMAX.loadInterstitial(adUnitId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// /// 开始定时器
|
||||||
|
// void _startTimer() {
|
||||||
|
// _timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
|
||||||
|
// if (_timeCount > 0) {
|
||||||
|
// _timeCount--;
|
||||||
|
// LogPrint.d('广告间隔倒计时$_timeCount秒');
|
||||||
|
// } else {
|
||||||
|
// _stopTimer();
|
||||||
|
// LogPrint.d('广告间隔计时停止');
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /// 停止定时器
|
||||||
|
// void _stopTimer() {
|
||||||
|
// _timer?.cancel();
|
||||||
|
// _timer = null;
|
||||||
|
// _timeCount = 30;
|
||||||
|
// }
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/applovin_max/applovin_manage.dart';
|
||||||
import 'package:now_wallpaper/generated/assets.dart';
|
import 'package:now_wallpaper/generated/assets.dart';
|
||||||
import 'package:now_wallpaper/res/themes/app_colors.dart';
|
import 'package:now_wallpaper/res/themes/app_colors.dart';
|
||||||
|
|
||||||
@ -15,12 +16,14 @@ class BaseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
this.backWidget,
|
this.backWidget,
|
||||||
this.titleStyle,
|
this.titleStyle,
|
||||||
|
this.onBackTap,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Color? backgroundColor;
|
final Color? backgroundColor;
|
||||||
final Widget? backWidget;
|
final Widget? backWidget;
|
||||||
final String title;
|
final String title;
|
||||||
final TextStyle? titleStyle;
|
final TextStyle? titleStyle;
|
||||||
|
final Function()? onBackTap;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -35,7 +38,10 @@ class BaseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: Get.back,
|
onTap: onBackTap ?? () async {
|
||||||
|
await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId3);
|
||||||
|
Get.back();
|
||||||
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(10).w,
|
padding: const EdgeInsets.all(10).w,
|
||||||
child: Image.asset(
|
child: Image.asset(
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
// Description: 设置壁纸插件
|
// Description: 设置壁纸插件
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:now_wallpaper/common/utils/log_print.dart';
|
||||||
|
|
||||||
class SetWallpaper {
|
class SetWallpaper {
|
||||||
static const MethodChannel _channel = MethodChannel('set_wallpaper');
|
static const MethodChannel _channel = MethodChannel('set_wallpaper');
|
||||||
@ -13,10 +14,10 @@ class SetWallpaper {
|
|||||||
"path": path,
|
"path": path,
|
||||||
"wallpaperType": wallpaperType // 0 for home screen, 1 for lock screen, 2 for both
|
"wallpaperType": wallpaperType // 0 for home screen, 1 for lock screen, 2 for both
|
||||||
});
|
});
|
||||||
print(result);
|
LogPrint.d(result);
|
||||||
return result;
|
return result;
|
||||||
} on PlatformException catch (e) {
|
} on PlatformException catch (e) {
|
||||||
print('Failed to set wallpaper: ${e.message}.');
|
LogPrint.e('Failed to set wallpaper: ${e.message}.');
|
||||||
return 'Failed to set wallpaper: ${e.message}.';
|
return 'Failed to set wallpaper: ${e.message}.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/applovin_max/applovin_manage.dart';
|
||||||
import 'package:now_wallpaper/common/components/easy_loading.dart';
|
import 'package:now_wallpaper/common/components/easy_loading.dart';
|
||||||
import 'package:now_wallpaper/common/storage/hive_storage.dart';
|
import 'package:now_wallpaper/common/storage/hive_storage.dart';
|
||||||
import 'package:now_wallpaper/res/themes/app_themes.dart';
|
import 'package:now_wallpaper/res/themes/app_themes.dart';
|
||||||
@ -11,6 +13,17 @@ import 'package:now_wallpaper/res/values/strings.dart';
|
|||||||
import 'package:now_wallpaper/routes/app_pages.dart';
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// 竖屏
|
||||||
|
SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.portraitUp,
|
||||||
|
DeviceOrientation.portraitDown,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 初始化广告sdk
|
||||||
|
await ApplovinManage().initApplovin();
|
||||||
|
|
||||||
// 初始化Hive
|
// 初始化Hive
|
||||||
await initHive();
|
await initHive();
|
||||||
|
|
||||||
@ -46,7 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
darkTheme: darkTheme,
|
darkTheme: darkTheme,
|
||||||
themeMode: ThemeMode.dark,
|
themeMode: ThemeMode.dark,
|
||||||
getPages: AppPages.routes,
|
getPages: AppPages.routes,
|
||||||
initialRoute: AppPages.root,
|
initialRoute: AppPages.splashScreen,
|
||||||
builder: (context, widget) {
|
builder: (context, widget) {
|
||||||
widget = easyLoading(context, widget);
|
widget = easyLoading(context, widget);
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
||||||
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
||||||
import 'package:now_wallpaper/modules/root/root_controller.dart';
|
import 'package:now_wallpaper/modules/home/home_controller.dart';
|
||||||
import 'package:now_wallpaper/routes/app_pages.dart';
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
class CatalogController extends GetxController {
|
class CatalogController extends GetxController {
|
||||||
@ -16,7 +16,7 @@ class CatalogController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void getData() {
|
void getData() {
|
||||||
wallpaperModelList = RootController.to.wallpaperModelList;
|
wallpaperModelList = HomeController.to.wallpaperModelList;
|
||||||
viewState = wallpaperModelList.isNotEmpty ? ViewState.normal : ViewState.empty;
|
viewState = wallpaperModelList.isNotEmpty ? ViewState.normal : ViewState.empty;
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@ -32,8 +32,8 @@ class CatalogController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onTapSingleCls(WallpaperModel wallpaperModel) {
|
void onTapSingleCls(WallpaperModel wallpaperModel) {
|
||||||
// 进入单个分类页面
|
// 进入分类详情页面
|
||||||
Get.toNamed(AppPages.singleCls, arguments: wallpaperModel);
|
Get.toNamed(AppPages.clsDet, arguments: wallpaperModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 点击壁纸
|
/// 点击壁纸
|
||||||
|
|||||||
9
lib/modules/cls_det/cls_det_binding.dart
Normal file
9
lib/modules/cls_det/cls_det_binding.dart
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/modules/cls_det/cls_det_controller.dart';
|
||||||
|
|
||||||
|
class ClsDetBinding extends Bindings {
|
||||||
|
@override
|
||||||
|
void dependencies() {
|
||||||
|
Get.lazyPut(() => ClsDetController());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
||||||
import 'package:now_wallpaper/routes/app_pages.dart';
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
class SingleClsController extends GetxController {
|
class ClsDetController extends GetxController {
|
||||||
late final List<WallpaperData> wallpaperDataList;
|
late final List<WallpaperData> wallpaperDataList;
|
||||||
late final String clsName;
|
late final String clsName;
|
||||||
|
|
||||||
@ -5,10 +5,10 @@ import 'package:get/get.dart';
|
|||||||
import 'package:now_wallpaper/common/components/image_network_widget.dart';
|
import 'package:now_wallpaper/common/components/image_network_widget.dart';
|
||||||
import 'package:now_wallpaper/common/components/navigation_bar/base_appbar.dart';
|
import 'package:now_wallpaper/common/components/navigation_bar/base_appbar.dart';
|
||||||
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
||||||
import 'package:now_wallpaper/modules/single_cls/single_cls_controller.dart';
|
import 'package:now_wallpaper/modules/cls_det/cls_det_controller.dart';
|
||||||
|
|
||||||
class SingleClsView extends GetView<SingleClsController> {
|
class ClsDetView extends GetView<ClsDetController> {
|
||||||
const SingleClsView({super.key});
|
const ClsDetView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -3,7 +3,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
||||||
import 'package:now_wallpaper/common/utils/obj_util.dart';
|
import 'package:now_wallpaper/common/utils/obj_util.dart';
|
||||||
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
||||||
import 'package:now_wallpaper/modules/root/root_controller.dart';
|
import 'package:now_wallpaper/modules/home/home_controller.dart';
|
||||||
import 'package:now_wallpaper/routes/app_pages.dart';
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
class DiscoverController extends GetxController {
|
class DiscoverController extends GetxController {
|
||||||
@ -28,15 +28,15 @@ class DiscoverController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void getData() {
|
void getData() {
|
||||||
todayNewestData = RootController.to.getRandomCls();
|
todayNewestData = HomeController.to.getRandomCls();
|
||||||
if (todayNewestData != null && todayNewestData!.data != null && todayNewestData!.data!.length >= 3) {
|
if (todayNewestData != null && todayNewestData!.data != null && todayNewestData!.data!.length >= 3) {
|
||||||
clsName = ObjUtil.getStr(todayNewestData!.name);
|
clsName = ObjUtil.getStr(todayNewestData!.name);
|
||||||
var flatList = todayNewestData!.data!.map((e) => e).toList();
|
var flatList = todayNewestData!.data!.map((e) => e).toList();
|
||||||
// 随机打乱此列表中的元素,再取前3个元素
|
// 随机打乱此列表中的元素,再取前3个元素
|
||||||
todayNewestList = (flatList..shuffle()).take(3).toList();
|
todayNewestList = (flatList..shuffle()).take(3).toList();
|
||||||
}
|
}
|
||||||
viewState = RootController.to.viewState;
|
viewState = HomeController.to.viewState;
|
||||||
allWallpaper = RootController.to.wallpaperModelList.expand((element) => element.data ?? <WallpaperData>[]).toList();
|
allWallpaper = HomeController.to.wallpaperModelList.expand((element) => element.data ?? <WallpaperData>[]).toList();
|
||||||
_getDataToShow();
|
_getDataToShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,8 @@ class DiscoverController extends GetxController {
|
|||||||
|
|
||||||
/// 点击今日最新
|
/// 点击今日最新
|
||||||
void onTapTodayNewest() {
|
void onTapTodayNewest() {
|
||||||
// 进入单个分类页面
|
// 进入分类详情页面
|
||||||
Get.toNamed(AppPages.singleCls, arguments: todayNewestData);
|
Get.toNamed(AppPages.clsDet, arguments: todayNewestData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 点击壁纸
|
/// 点击壁纸
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import 'package:now_wallpaper/common/components/dialog/remind_dialog.dart';
|
|||||||
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
||||||
import 'package:now_wallpaper/common/storage/favorite_data.dart';
|
import 'package:now_wallpaper/common/storage/favorite_data.dart';
|
||||||
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
||||||
import 'package:now_wallpaper/modules/root/root_controller.dart';
|
import 'package:now_wallpaper/modules/home/home_controller.dart';
|
||||||
import 'package:now_wallpaper/routes/app_pages.dart';
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
class FavoriteController extends GetxController {
|
class FavoriteController extends GetxController {
|
||||||
@ -33,7 +33,7 @@ class FavoriteController extends GetxController {
|
|||||||
/// 获取今日最热门壁纸
|
/// 获取今日最热门壁纸
|
||||||
void getTodayHottestList() {
|
void getTodayHottestList() {
|
||||||
// 从分类中随机取3张壁纸
|
// 从分类中随机取3张壁纸
|
||||||
todayHottestData = RootController.to.getRandomCls();
|
todayHottestData = HomeController.to.getRandomCls();
|
||||||
if (todayHottestData != null && todayHottestData!.data != null && todayHottestData!.data!.length >= 3) {
|
if (todayHottestData != null && todayHottestData!.data != null && todayHottestData!.data!.length >= 3) {
|
||||||
var flatList = todayHottestData!.data!.map((e) => e).toList();
|
var flatList = todayHottestData!.data!.map((e) => e).toList();
|
||||||
todayHottestList = (flatList..shuffle()).take(3).toList();
|
todayHottestList = (flatList..shuffle()).take(3).toList();
|
||||||
@ -81,7 +81,7 @@ class FavoriteController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onTapViewMore() {
|
void onTapViewMore() {
|
||||||
// 进入单个分类页面
|
// 进入分类详情页面
|
||||||
Get.toNamed(AppPages.singleCls, arguments: todayHottestData);
|
Get.toNamed(AppPages.clsDet, arguments: todayHottestData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
lib/modules/home/home_binding.dart
Normal file
9
lib/modules/home/home_binding.dart
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/modules/home/home_controller.dart';
|
||||||
|
|
||||||
|
class HomeBinding extends Bindings {
|
||||||
|
@override
|
||||||
|
void dependencies() {
|
||||||
|
Get.lazyPut(() => HomeController());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/applovin_max/applovin_manage.dart';
|
||||||
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
import 'package:now_wallpaper/common/components/view_state_widget.dart';
|
||||||
import 'package:now_wallpaper/generated/assets.dart';
|
import 'package:now_wallpaper/generated/assets.dart';
|
||||||
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
import 'package:now_wallpaper/models/wallpaper_model.dart';
|
||||||
@ -14,8 +16,8 @@ import 'package:now_wallpaper/modules/favorite/favorite_controller.dart';
|
|||||||
import 'package:now_wallpaper/modules/favorite/favorite_view.dart';
|
import 'package:now_wallpaper/modules/favorite/favorite_view.dart';
|
||||||
import 'package:now_wallpaper/routes/app_pages.dart';
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
class RootController extends GetxController {
|
class HomeController extends GetxController with WidgetsBindingObserver {
|
||||||
static RootController get to => Get.find<RootController>();
|
static HomeController get to => Get.find<HomeController>();
|
||||||
final pages = [
|
final pages = [
|
||||||
PageItem('Discover', [Assets.imagesDiscoverUnchecked, Assets.imagesDiscoverSelected], const DiscoverView()),
|
PageItem('Discover', [Assets.imagesDiscoverUnchecked, Assets.imagesDiscoverSelected], const DiscoverView()),
|
||||||
PageItem('Favorite', [Assets.imagesFavoriteUnchecked, Assets.imagesFavoriteSelected], const FavoriteView()),
|
PageItem('Favorite', [Assets.imagesFavoriteUnchecked, Assets.imagesFavoriteSelected], const FavoriteView()),
|
||||||
@ -29,6 +31,7 @@ class RootController extends GetxController {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
pageController = PageController(initialPage: currentIndex.value);
|
pageController = PageController(initialPage: currentIndex.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,18 +43,34 @@ class RootController extends GetxController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
pageController.dispose();
|
pageController.dispose();
|
||||||
super.onClose();
|
super.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
|
||||||
|
switch (state) {
|
||||||
|
case AppLifecycleState.resumed:
|
||||||
|
await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId1);
|
||||||
|
break;
|
||||||
|
case AppLifecycleState.inactive:
|
||||||
|
case AppLifecycleState.hidden:
|
||||||
|
case AppLifecycleState.paused:
|
||||||
|
case AppLifecycleState.detached:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// PageView页面改变回调
|
/// PageView页面改变回调
|
||||||
void onPageChanged(int index) {
|
void onPageChanged(int index) {
|
||||||
currentIndex.value = index;
|
currentIndex.value = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 点击BottomNavigationBar
|
/// 点击BottomNavigationBar
|
||||||
void onTapNavigationBar(int index) {
|
void onTapNavigationBar(int index) async {
|
||||||
pageController.jumpToPage(index);
|
pageController.jumpToPage(index);
|
||||||
|
await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 点击设置
|
/// 点击设置
|
||||||
@ -3,10 +3,10 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:now_wallpaper/common/components/keep_alive_wrapper.dart';
|
import 'package:now_wallpaper/common/components/keep_alive_wrapper.dart';
|
||||||
import 'package:now_wallpaper/common/components/navigation_bar/title_bar_widget.dart';
|
import 'package:now_wallpaper/common/components/navigation_bar/title_bar_widget.dart';
|
||||||
import 'package:now_wallpaper/modules/root/root_controller.dart';
|
import 'package:now_wallpaper/modules/home/home_controller.dart';
|
||||||
|
|
||||||
class RootView extends GetView<RootController> {
|
class HomeView extends GetView<HomeController> {
|
||||||
const RootView({super.key});
|
const HomeView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -1,9 +0,0 @@
|
|||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:now_wallpaper/modules/root/root_controller.dart';
|
|
||||||
|
|
||||||
class RootBinding extends Bindings {
|
|
||||||
@override
|
|
||||||
void dependencies() {
|
|
||||||
Get.lazyPut(() => RootController());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
import 'package:get/get.dart';
|
|
||||||
|
|
||||||
import 'single_cls_controller.dart';
|
|
||||||
|
|
||||||
class SingleClsBinding extends Bindings {
|
|
||||||
@override
|
|
||||||
void dependencies() {
|
|
||||||
Get.lazyPut(() => SingleClsController());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
10
lib/modules/splash_screen/splash_screen_binding.dart
Normal file
10
lib/modules/splash_screen/splash_screen_binding.dart
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
import 'splash_screen_controller.dart';
|
||||||
|
|
||||||
|
class SplashScreenBinding extends Bindings {
|
||||||
|
@override
|
||||||
|
void dependencies() {
|
||||||
|
Get.lazyPut(() => SplashScreenController());
|
||||||
|
}
|
||||||
|
}
|
||||||
48
lib/modules/splash_screen/splash_screen_controller.dart
Normal file
48
lib/modules/splash_screen/splash_screen_controller.dart
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/applovin_max/applovin_manage.dart';
|
||||||
|
import 'package:now_wallpaper/routes/app_pages.dart';
|
||||||
|
|
||||||
|
class SplashScreenController extends GetxController {
|
||||||
|
Timer? _timer;
|
||||||
|
int _timeCount = 15;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
ApplovinManage().initializeInterstitialAds(
|
||||||
|
onAdLoadedCallback: _openHomePage,
|
||||||
|
);
|
||||||
|
_startTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
_stopTimer();
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 开始定时器
|
||||||
|
void _startTimer() {
|
||||||
|
_timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
|
||||||
|
if (_timeCount <= 0) {
|
||||||
|
_openHomePage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_timeCount--;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止定时器
|
||||||
|
void _stopTimer() {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 打开首页
|
||||||
|
void _openHomePage() {
|
||||||
|
_stopTimer();
|
||||||
|
Get.offAndToNamed(AppPages.home);
|
||||||
|
}
|
||||||
|
}
|
||||||
75
lib/modules/splash_screen/splash_screen_view.dart
Normal file
75
lib/modules/splash_screen/splash_screen_view.dart
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:now_wallpaper/generated/assets.dart';
|
||||||
|
import 'package:now_wallpaper/modules/splash_screen/splash_screen_controller.dart';
|
||||||
|
import 'package:now_wallpaper/res/values/strings.dart';
|
||||||
|
|
||||||
|
class SplashScreenView extends GetView<SplashScreenController> {
|
||||||
|
const SplashScreenView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
Get.find<SplashScreenController>();
|
||||||
|
return Scaffold(
|
||||||
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
_buildIconName(),
|
||||||
|
_buildProgress(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildIconName() {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Image.asset(
|
||||||
|
Assets.iconIconApp,
|
||||||
|
width: 96.w,
|
||||||
|
height: 96.w,
|
||||||
|
),
|
||||||
|
SizedBox(height: 20.h),
|
||||||
|
Text(
|
||||||
|
appName,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 22.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildProgress() {
|
||||||
|
return Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
margin: const EdgeInsets.only(bottom: 60).h,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 0.5.sw,
|
||||||
|
child: LinearProgressIndicator(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
valueColor: const AlwaysStoppedAnimation<Color>(Colors.grey),
|
||||||
|
borderRadius: BorderRadius.circular(8).r,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 14.h),
|
||||||
|
Text(
|
||||||
|
'Resource Loading...',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12.sp,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||||
|
import 'package:now_wallpaper/applovin_max/applovin_manage.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:now_wallpaper/common/components/dialog/bottomsheet_dialog.dart';
|
import 'package:now_wallpaper/common/components/dialog/bottomsheet_dialog.dart';
|
||||||
import 'package:now_wallpaper/common/components/easy_loading.dart';
|
import 'package:now_wallpaper/common/components/easy_loading.dart';
|
||||||
@ -97,6 +98,7 @@ class WallpaperDetController extends GetxController {
|
|||||||
|
|
||||||
/// 设置壁纸
|
/// 设置壁纸
|
||||||
void onTapSetWallpaper() async {
|
void onTapSetWallpaper() async {
|
||||||
|
await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId2);
|
||||||
BottomSheetDialog.show((location) async {
|
BottomSheetDialog.show((location) async {
|
||||||
if (showBlur.value) {
|
if (showBlur.value) {
|
||||||
await _captureScreenshot();
|
await _captureScreenshot();
|
||||||
@ -152,4 +154,10 @@ class WallpaperDetController extends GetxController {
|
|||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 显示广告
|
||||||
|
Future<void> showAd() async {
|
||||||
|
await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId3);
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class WallpaperDetView extends GetView<WallpaperDetController> {
|
|||||||
/// 返回按钮
|
/// 返回按钮
|
||||||
Widget _buildBackWidget() {
|
Widget _buildBackWidget() {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: Get.back,
|
onTap: controller.showAd,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(left: 10).w,
|
padding: const EdgeInsets.only(left: 10).w,
|
||||||
child: ClipOval(
|
child: ClipOval(
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import 'package:now_wallpaper/res/themes/app_colors.dart';
|
|||||||
import 'package:now_wallpaper/res/themes/app_sizes.dart';
|
import 'package:now_wallpaper/res/themes/app_sizes.dart';
|
||||||
|
|
||||||
/// 深色主题
|
/// 深色主题
|
||||||
ThemeData darkTheme = ThemeData.dark(useMaterial3: false).copyWith(
|
ThemeData darkTheme = ThemeData.dark(useMaterial3: true).copyWith(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: seedColor, primary: Colors.white),
|
colorScheme: ColorScheme.fromSeed(seedColor: seedColor, primary: Colors.white),
|
||||||
scaffoldBackgroundColor: seedColor,
|
scaffoldBackgroundColor: seedColor,
|
||||||
bottomNavigationBarTheme: BottomNavigationBarThemeData(
|
bottomNavigationBarTheme: BottomNavigationBarThemeData(
|
||||||
|
|||||||
@ -5,12 +5,14 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:now_wallpaper/modules/about/about_binding.dart';
|
import 'package:now_wallpaper/modules/about/about_binding.dart';
|
||||||
import 'package:now_wallpaper/modules/about/about_view.dart';
|
import 'package:now_wallpaper/modules/about/about_view.dart';
|
||||||
import 'package:now_wallpaper/modules/root/root_binding.dart';
|
import 'package:now_wallpaper/modules/cls_det/cls_det_binding.dart';
|
||||||
import 'package:now_wallpaper/modules/root/root_view.dart';
|
import 'package:now_wallpaper/modules/cls_det/cls_det_view.dart';
|
||||||
|
import 'package:now_wallpaper/modules/home/home_binding.dart';
|
||||||
|
import 'package:now_wallpaper/modules/home/home_view.dart';
|
||||||
import 'package:now_wallpaper/modules/settings/settings_binding.dart';
|
import 'package:now_wallpaper/modules/settings/settings_binding.dart';
|
||||||
import 'package:now_wallpaper/modules/settings/settings_view.dart';
|
import 'package:now_wallpaper/modules/settings/settings_view.dart';
|
||||||
import 'package:now_wallpaper/modules/single_cls/single_cls_binding.dart';
|
import 'package:now_wallpaper/modules/splash_screen/splash_screen_binding.dart';
|
||||||
import 'package:now_wallpaper/modules/single_cls/single_cls_view.dart';
|
import 'package:now_wallpaper/modules/splash_screen/splash_screen_view.dart';
|
||||||
import 'package:now_wallpaper/modules/wallpaper_det/wallpaper_det_binding.dart';
|
import 'package:now_wallpaper/modules/wallpaper_det/wallpaper_det_binding.dart';
|
||||||
import 'package:now_wallpaper/modules/wallpaper_det/wallpaper_det_view.dart';
|
import 'package:now_wallpaper/modules/wallpaper_det/wallpaper_det_view.dart';
|
||||||
import 'package:now_wallpaper/modules/web_page/web_page_binding.dart';
|
import 'package:now_wallpaper/modules/web_page/web_page_binding.dart';
|
||||||
@ -19,24 +21,37 @@ import 'package:now_wallpaper/modules/web_page/web_page_view.dart';
|
|||||||
class AppPages {
|
class AppPages {
|
||||||
AppPages._();
|
AppPages._();
|
||||||
|
|
||||||
/// 根路由
|
/// 启动页面
|
||||||
static const root = '/';
|
static const splashScreen = '/splash_screen';
|
||||||
|
|
||||||
|
/// 首页
|
||||||
|
static const home = '/home';
|
||||||
|
|
||||||
/// 壁纸详情
|
/// 壁纸详情
|
||||||
static const wallpaperDet = '/wallpaper_det';
|
static const wallpaperDet = '/wallpaper_det';
|
||||||
/// 单个分类
|
|
||||||
static const singleCls = '/single_cls';
|
/// 分类详情
|
||||||
|
static const clsDet = '/cls_det';
|
||||||
|
|
||||||
/// 设置
|
/// 设置
|
||||||
static const settings = '/settings';
|
static const settings = '/settings';
|
||||||
|
|
||||||
/// 关于
|
/// 关于
|
||||||
static const about = '/about';
|
static const about = '/about';
|
||||||
|
|
||||||
/// WebView页面
|
/// WebView页面
|
||||||
static const webPage = '/web_page';
|
static const webPage = '/web_page';
|
||||||
|
|
||||||
static final routes = [
|
static final routes = [
|
||||||
GetPage(
|
GetPage(
|
||||||
name: root,
|
name: splashScreen,
|
||||||
page: () => const RootView(),
|
page: () => const SplashScreenView(),
|
||||||
binding: RootBinding(),
|
binding: SplashScreenBinding(),
|
||||||
|
),
|
||||||
|
GetPage(
|
||||||
|
name: home,
|
||||||
|
page: () => const HomeView(),
|
||||||
|
binding: HomeBinding(),
|
||||||
),
|
),
|
||||||
GetPage(
|
GetPage(
|
||||||
name: wallpaperDet,
|
name: wallpaperDet,
|
||||||
@ -44,9 +59,9 @@ class AppPages {
|
|||||||
binding: WallpaperDetBinding(),
|
binding: WallpaperDetBinding(),
|
||||||
),
|
),
|
||||||
GetPage(
|
GetPage(
|
||||||
name: singleCls,
|
name: clsDet,
|
||||||
page: () => const SingleClsView(),
|
page: () => const ClsDetView(),
|
||||||
binding: SingleClsBinding(),
|
binding: ClsDetBinding(),
|
||||||
),
|
),
|
||||||
GetPage(
|
GetPage(
|
||||||
name: settings,
|
name: settings,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.0.0+1
|
version: 1.0.1+2
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.3.4 <4.0.0'
|
sdk: '>=3.3.4 <4.0.0'
|
||||||
@ -92,6 +92,9 @@ dependencies:
|
|||||||
# 分享
|
# 分享
|
||||||
share_plus: ^9.0.0
|
share_plus: ^9.0.0
|
||||||
|
|
||||||
|
# AppLovin
|
||||||
|
applovin_max: ^3.10.0
|
||||||
|
|
||||||
flutter_launcher_icons:
|
flutter_launcher_icons:
|
||||||
android: "launcher_icon"
|
android: "launcher_icon"
|
||||||
ios: true
|
ios: true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user