Browse Source

优化初始化进度条

weicu
lxm 1 year ago
parent
commit
3f32cb2dea
  1. 12
      lib/modules/home/views/home_view.dart
  2. 4
      lib/modules/login/controllers/login_controller.dart
  3. 1
      lib/modules/login/views/login_view.dart
  4. 21
      lib/modules/splash/controllers/splash_controller.dart
  5. 69
      lib/modules/splash/views/splash_view.dart

12
lib/modules/home/views/home_view.dart

@ -157,6 +157,9 @@ class HomeView extends GetView<HomeController> {
child: PageView( child: PageView(
children: [ children: [
Center( Center(
child: ClipRRect(
// 添加 ClipRRect 来实现圆角
borderRadius: BorderRadius.circular(16.r), // 使用与其他部件一致的圆角大小
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
height: 200.h, height: 200.h,
@ -168,7 +171,11 @@ class HomeView extends GetView<HomeController> {
), ),
), ),
), ),
),
Center( Center(
child: ClipRRect(
// 添加 ClipRRect
borderRadius: BorderRadius.circular(16.r),
child: Image.asset( child: Image.asset(
isDarkMode isDarkMode
? 'assets/images/headphone_dark.png' ? 'assets/images/headphone_dark.png'
@ -177,7 +184,11 @@ class HomeView extends GetView<HomeController> {
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
),
Center( Center(
child: ClipRRect(
// 添加 ClipRRect
borderRadius: BorderRadius.circular(16.r),
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
height: 200.h, height: 200.h,
@ -186,6 +197,7 @@ class HomeView extends GetView<HomeController> {
? 'assets/images/glasses_light.png' ? 'assets/images/glasses_light.png'
: 'assets/images/glasses_light.png', : 'assets/images/glasses_light.png',
fit: BoxFit.fitWidth, fit: BoxFit.fitWidth,
),
), ),
), ),
), ),

4
lib/modules/login/controllers/login_controller.dart

@ -550,7 +550,7 @@ class LoginController extends GetxController {
requestLogin({ requestLogin({
"mail": facebook.email, "mail": facebook.email,
"phone": "", "phone": "",
"stype": 5, "stype": loginType,
"vcode": "", "vcode": "",
"ttoken": facebook.token, "ttoken": facebook.token,
"phonemodel": "", "phonemodel": "",
@ -579,7 +579,7 @@ class LoginController extends GetxController {
requestLogin({ requestLogin({
"mail": google.email, "mail": google.email,
"phone": "", "phone": "",
"stype": 5, "stype": loginType,
"vcode": "", "vcode": "",
"ttoken": google.token, "ttoken": google.token,
"phonemodel": "", "phonemodel": "",

1
lib/modules/login/views/login_view.dart

@ -575,7 +575,6 @@ class LoginView extends GetView<LoginController> {
GestureDetector( GestureDetector(
onTap: () { onTap: () {
String url = 'https://www.deepsoud.com/yhxy.html'; String url = 'https://www.deepsoud.com/yhxy.html';
print('----------${Get.locale?.toString()}');
if (Get.locale?.toString() != 'zh_CN') { if (Get.locale?.toString() != 'zh_CN') {
url = 'https://www.deepsoud.com/yhxy_en.html'; url = 'https://www.deepsoud.com/yhxy_en.html';
} }

21
lib/modules/splash/controllers/splash_controller.dart

@ -21,7 +21,7 @@ class SplashController extends GetxController {
bool get isResourceLoaded => _isResourceLoaded.value; bool get isResourceLoaded => _isResourceLoaded.value;
// 版本号 // 版本号
final String version = 'v1.0.0'; //final String version = 'V1.0.0';
// 主题服务 // 主题服务
final ThemeService _themeService = ThemeService(); final ThemeService _themeService = ThemeService();
@ -32,20 +32,29 @@ class SplashController extends GetxController {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
_startLoadingAnimation(); _startLoadingAnimation();
_loadAppResources(); _loadAppResources();
_initMapSDK();
});
}
// 初始化地图SDK
void _initMapSDK() {
try {
AmapFlutter().initSdk( AmapFlutter().initSdk(
iosKey: "a4a1394fe817c2f86a424b897b4a9af4", iosKey: "a4a1394fe817c2f86a424b897b4a9af4",
androidKey: "e5fdc9605eabdeb5626f18f5721f343d", androidKey: "e5fdc9605eabdeb5626f18f5721f343d",
); );
}); } catch (e) {
print('地图SDK初始化失败: $e');
}
} }
// 进度条动画(持续2秒) // 进度条动画(持续2秒)
void _startLoadingAnimation() { void _startLoadingAnimation() {
const totalDuration = 500; // 动画总时长2秒 const totalDuration = 1500; // 动画总时长增加到1.5秒
const steps = totalDuration ~/ 50; // 40次更新(50ms间隔) const steps = totalDuration ~/ 30; // 30的间隔,更平滑的动画
final stepValue = 1.0 / steps; const stepValue = 1.0 / steps;
Timer.periodic(const Duration(milliseconds: 50), (timer) { Timer.periodic(const Duration(milliseconds: 30), (timer) {
if (_loadingProgress.value < 1.0) { if (_loadingProgress.value < 1.0) {
_loadingProgress.value += stepValue; _loadingProgress.value += stepValue;
} else { } else {

69
lib/modules/splash/views/splash_view.dart

@ -40,7 +40,7 @@ class SplashView extends GetView<SplashController> {
), ),
// 版本号 // 版本号
_buildVersionInfo(isDarkMode), //_buildVersionInfo(isDarkMode),
], ],
), ),
); );
@ -148,6 +148,7 @@ class SplashView extends GetView<SplashController> {
padding: EdgeInsets.symmetric(horizontal: 80.w), padding: EdgeInsets.symmetric(horizontal: 80.w),
child: Stack( child: Stack(
children: [ children: [
// 背景条
Container( Container(
height: 4.h, height: 4.h,
decoration: BoxDecoration( decoration: BoxDecoration(
@ -155,23 +156,28 @@ class SplashView extends GetView<SplashController> {
borderRadius: BorderRadius.circular(2.r), borderRadius: BorderRadius.circular(2.r),
), ),
), ),
// 进度条
Obx(() { Obx(() {
final progress = controller.loadingProgress; final progress = controller.loadingProgress;
return LayoutBuilder( return AnimatedContainer(
builder: (context, constraints) { duration: const Duration(milliseconds: 200),
return Container( height: 4.h,
height: 4.h, width: 240.w * progress, // 使用固定宽度乘以进度
width: constraints.maxWidth * progress, decoration: BoxDecoration(
decoration: BoxDecoration( gradient: const LinearGradient(
gradient: const LinearGradient( begin: Alignment.centerLeft,
begin: Alignment.centerLeft, end: Alignment.centerRight,
end: Alignment.centerRight, colors: [Colors.blue, Colors.purple],
colors: [Colors.blue, Colors.purple], ),
), borderRadius: BorderRadius.circular(2.r),
borderRadius: BorderRadius.circular(2.r), boxShadow: [
BoxShadow(
color: Colors.blue.withOpacity(0.3),
blurRadius: 5,
offset: const Offset(0, 1),
), ),
); ],
}, ),
); );
}), }),
], ],
@ -201,20 +207,21 @@ class SplashView extends GetView<SplashController> {
} }
// 版本信息 // 版本信息
Widget _buildVersionInfo(bool isDarkMode) { // 暂时不需要版本号显示,保留代码以备将来使用
return Positioned( // Widget _buildVersionInfo(bool isDarkMode) {
bottom: 32.h, // return Positioned(
left: 0, // bottom: 32.h,
right: 0, // left: 0,
child: Center( // right: 0,
child: Text( // child: Center(
controller.version, // child: Text(
style: TextStyle( // controller.version,
fontSize: 12.sp, // style: TextStyle(
color: isDarkMode ? Colors.grey[500] : Colors.grey[400], // fontSize: 12.sp,
), // color: isDarkMode ? Colors.grey[500] : Colors.grey[400],
), // ),
), // ),
); // ),
} // );
// }
} }

Loading…
Cancel
Save