109 lines
3.3 KiB
Dart
109 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:wallpaperx/ads/interstitial_ad_manage.dart';
|
|
import 'package:wallpaperx/common/components/view_state_widget.dart';
|
|
import 'package:wallpaperx/common/utils/shared_util.dart';
|
|
import 'package:wallpaperx/entity/userinfo_model.dart';
|
|
import 'package:wallpaperx/generated/assets.dart';
|
|
import 'package:wallpaperx/global/app_lifecycle_reactor.dart';
|
|
import 'package:wallpaperx/global/app_tracking_transparency_manager.dart';
|
|
import 'package:wallpaperx/page/custom/custom_view.dart';
|
|
import 'package:wallpaperx/page/library/library_view.dart';
|
|
import 'package:wallpaperx/page/recommend/recommend_view.dart';
|
|
import 'package:wallpaperx/page/settings/settings_view.dart';
|
|
import 'package:wallpaperx/routes/app_pages.dart';
|
|
|
|
class HomeController extends GetxController {
|
|
static HomeController get to => Get.find<HomeController>();
|
|
final pages = [
|
|
PageItem(Assets.imagesRecommendSelected, const RecommendView()),
|
|
PageItem(Assets.imagesCollectionSelected, const LibraryView()),
|
|
PageItem(Assets.imagesCustomSelected, const CustomView()),
|
|
PageItem(Assets.imagesSettingSelected, const SettingsView()),
|
|
];
|
|
late PageController pageController;
|
|
var currentIndex = 0.obs;
|
|
var viewState = ViewState.loading;
|
|
UserinfoModel userinfo = UserinfoModel();
|
|
|
|
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
|
|
|
List<String> category = [
|
|
"Anime and Game Design",
|
|
"Brand and Visual Design",
|
|
"Architecture and Space Design",
|
|
"Product and Industrial Design",
|
|
"Outdoor and Nature",
|
|
"Styles and Themes",
|
|
"Characters and Fashion",
|
|
"Photography",
|
|
];
|
|
|
|
List<String> categoryImages = [
|
|
"assets/category/category_img_1.png",
|
|
"assets/category/category_img_2.png",
|
|
"assets/category/category_img_3.png",
|
|
"assets/category/category_img_4.png",
|
|
"assets/category/category_img_5.png",
|
|
"assets/category/category_img_6.png",
|
|
"assets/category/category_img_7.png",
|
|
"assets/category/category_img_8.png",
|
|
];
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
AppTrackingTransparencyManager().requestATT();
|
|
AppLifecycleReactor().listenToAppStateChanges();
|
|
|
|
loadUserInfo();
|
|
pageController = PageController(initialPage: currentIndex.value);
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
pageController.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
void openHomeDrawer() {
|
|
scaffoldKey.currentState?.openDrawer();
|
|
}
|
|
|
|
/// PageView页面改变回调
|
|
void onPageChanged(int index, {int? changeType}) {
|
|
currentIndex.value = index;
|
|
}
|
|
|
|
/// 点击BottomNavigationBar
|
|
void onTapNavigationBar(int index) {
|
|
pageController.jumpToPage(index);
|
|
}
|
|
|
|
/// 获取用户信息
|
|
void loadUserInfo({String? userId}) {
|
|
var loginAccount = UPCache.getInstance().get("loginAccount");
|
|
var map = UPCache.getInstance().getJson(loginAccount ?? "");
|
|
if (map != null) {
|
|
userinfo = UserinfoModel.fromJson(map);
|
|
}
|
|
}
|
|
|
|
/// 跳转分类
|
|
void toCategory(title, {String? jumpType}) {
|
|
InterstitialAdManager().showAdIfReady(onTap: () {
|
|
scaffoldKey.currentState?.openEndDrawer();
|
|
Get.toNamed(AppPages.category, arguments: {
|
|
'title': title,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
class PageItem {
|
|
late final String icons;
|
|
late final StatelessWidget widget;
|
|
|
|
PageItem(this.icons, this.widget);
|
|
}
|