import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:location/resource/assets.gen.dart'; import 'package:location/resource/colors.gen.dart'; import 'package:location/resource/string.gen.dart'; import 'package:location/utils/common_expand.dart'; import '../utils/common_style.dart'; class LocationPermissionDialog { static const String _tag = "LocationPermissionDialog"; static void show({required VoidCallback onNextStep}) { SmartDialog.show( tag: _tag, builder: (_) { if (Platform.isAndroid) { return CupertinoLocationView(onNextStep: onNextStep); } else { return CupertinoLocationView(onNextStep: onNextStep); } }); } static void dismiss() { SmartDialog.dismiss(tag: _tag); } } class AndroidLocationView extends Dialog { const AndroidLocationView({super.key}); } class CupertinoLocationView extends Dialog { final VoidCallback onNextStep; const CupertinoLocationView({super.key, required this.onNextStep}); @override Widget build(BuildContext context) { return IntrinsicHeight( child: Container( width: 300.w, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10.w), ), child: Column( children: [ Assets.images.bgDialogLocationPermissionIos .image(width: double.infinity), SizedBox(height: 34.w), SizedBox( width: 210.w, child: RichText( textAlign: TextAlign.center, text: TextSpan( style: TextStyle(fontSize: 14.sp, color: '#404040'.color), children: [ TextSpan(text: '为保位置展示在地图上,需要允许使用'), TextSpan( text: '位置权限', style: TextStyle( color: '#1448CC'.color, fontWeight: FontWeight.bold)), ]), ), ), SizedBox(height: 19.w), GestureDetector( onTap: () { LocationPermissionDialog.dismiss(); onNextStep.call(); }, child: Container( width: 252.w, height: 36.w, decoration: getPrimaryBtnDecoration(46.w), child: Center( child: Text(StringName.nextStep, style: TextStyle( fontSize: 16.sp, color: Colors.white, fontWeight: FontWeight.bold)), ), ), ), SizedBox(height: 23.w), ], ), ), ); } } class LocationAlwaysPermissionDialog { static const String _tag = "LocationAlwaysPermissionDialog"; static void show({required VoidCallback onNextStep}) { SmartDialog.show( tag: _tag, alignment: Alignment.bottomCenter, builder: (_) { if (Platform.isAndroid) { return CupertinoLocationAlwaysView(onNextStep: onNextStep); } else { return CupertinoLocationAlwaysView(onNextStep: onNextStep); } }); } static void dismiss() { SmartDialog.dismiss(tag: _tag); } } class CupertinoLocationAlwaysView extends Dialog { final VoidCallback onNextStep; final RxInt _currentPage = 0.obs; int get currentPage => _currentPage.value; final PageController pageController = PageController(initialPage: 0); final List pageList = [ Assets.images.imgDialogLocationAlwaysTip1.image(width: double.infinity), Assets.images.imgDialogLocationAlwaysTip2.image(width: double.infinity), Assets.images.imgDialogLocationAlwaysTip3.image(width: double.infinity), ]; CupertinoLocationAlwaysView({super.key, required this.onNextStep}); @override Widget build(BuildContext context) { return IntrinsicHeight( child: Container( width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(16.w), topRight: Radius.circular(16.w), ), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox(height: 28.w), Container( margin: EdgeInsets.symmetric(horizontal: 16.w), child: RichText( text: TextSpan( style: TextStyle(fontSize: 20.sp, color: '#333333'.color), children: [ TextSpan( text: '应用使用需开启', style: TextStyle(fontWeight: FontWeight.bold)), TextSpan( text: '精准位置', style: TextStyle( color: '#1448CC'.color, fontWeight: FontWeight.bold)), TextSpan( text: '权限', style: TextStyle(fontWeight: FontWeight.bold)) ]), ), ), Text(StringName.locationBackgroundAlwaysDesc, style: TextStyle(fontSize: 14.sp, color: '#666666'.color)), SizedBox(height: 24.w), SizedBox( width: 304.w, height: 230.w, child: PageView( onPageChanged: (index) { _currentPage.value = index; }, controller: pageController, children: pageList, ), ), SizedBox(height: 8.w), indicator(), SizedBox(height: 30.w), GestureDetector( onTap: () => onNextClick(), child: Container( decoration: getPrimaryBtnDecoration(46.w), width: 312.w, height: 44.w, child: Center( child: Text(StringName.nextStep, style: TextStyle(fontSize: 15.sp, color: Colors.white)), ), ), ), SizedBox(height: 28.w), ], ), ), ); } Widget indicator() { return Obx(() { return Row( mainAxisAlignment: MainAxisAlignment.center, children: List.generate(pageList.length, (index) { return Container( margin: EdgeInsets.symmetric(horizontal: 3.w), width: 6.w, height: 6.w, decoration: BoxDecoration( color: currentPage == index ? '#A7A7A7'.color : '#E5E5E5'.color, shape: BoxShape.circle, ), ); }), ); }); } void onNextClick() async { double? index = pageController.page; if (index == pageList.length - 1) { LocationAlwaysPermissionDialog.dismiss(); onNextStep.call(); return; } await pageController.nextPage( duration: const Duration(milliseconds: 300), curve: Curves.easeInOut); } }