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

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

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

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

@ -575,7 +575,6 @@ class LoginView extends GetView<LoginController> {
GestureDetector(
onTap: () {
String url = 'https://www.deepsoud.com/yhxy.html';
print('----------${Get.locale?.toString()}');
if (Get.locale?.toString() != 'zh_CN') {
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;
// 版本号
final String version = 'v1.0.0';
//final String version = 'V1.0.0';
// 主题服务
final ThemeService _themeService = ThemeService();
@ -32,20 +32,29 @@ class SplashController extends GetxController {
WidgetsBinding.instance.addPostFrameCallback((_) {
_startLoadingAnimation();
_loadAppResources();
_initMapSDK();
});
}
// 初始化地图SDK
void _initMapSDK() {
try {
AmapFlutter().initSdk(
iosKey: "a4a1394fe817c2f86a424b897b4a9af4",
androidKey: "e5fdc9605eabdeb5626f18f5721f343d",
);
});
} catch (e) {
print('地图SDK初始化失败: $e');
}
}
// 进度条动画(持续2秒)
void _startLoadingAnimation() {
const totalDuration = 500; // 动画总时长2秒
const steps = totalDuration ~/ 50; // 40次更新(50ms间隔)
final stepValue = 1.0 / steps;
const totalDuration = 1500; // 动画总时长增加到1.5秒
const steps = totalDuration ~/ 30; // 30的间隔,更平滑的动画
const stepValue = 1.0 / steps;
Timer.periodic(const Duration(milliseconds: 50), (timer) {
Timer.periodic(const Duration(milliseconds: 30), (timer) {
if (_loadingProgress.value < 1.0) {
_loadingProgress.value += stepValue;
} 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),
child: Stack(
children: [
// 背景条
Container(
height: 4.h,
decoration: BoxDecoration(
@ -155,23 +156,28 @@ class SplashView extends GetView<SplashController> {
borderRadius: BorderRadius.circular(2.r),
),
),
// 进度条
Obx(() {
final progress = controller.loadingProgress;
return LayoutBuilder(
builder: (context, constraints) {
return Container(
height: 4.h,
width: constraints.maxWidth * progress,
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.blue, Colors.purple],
),
borderRadius: BorderRadius.circular(2.r),
return AnimatedContainer(
duration: const Duration(milliseconds: 200),
height: 4.h,
width: 240.w * progress, // 使用固定宽度乘以进度
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.blue, Colors.purple],
),
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(
bottom: 32.h,
left: 0,
right: 0,
child: Center(
child: Text(
controller.version,
style: TextStyle(
fontSize: 12.sp,
color: isDarkMode ? Colors.grey[500] : Colors.grey[400],
),
),
),
);
}
// 暂时不需要版本号显示,保留代码以备将来使用
// Widget _buildVersionInfo(bool isDarkMode) {
// return Positioned(
// bottom: 32.h,
// left: 0,
// right: 0,
// child: Center(
// child: Text(
// controller.version,
// style: TextStyle(
// fontSize: 12.sp,
// color: isDarkMode ? Colors.grey[500] : Colors.grey[400],
// ),
// ),
// ),
// );
// }
}

Loading…
Cancel
Save