128 lines
5.6 KiB
Dart
128 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:proxibuy/core/config/app_colors.dart';
|
|
import 'package:proxibuy/core/gen/assets.gen.dart';
|
|
|
|
Future<void> showGPSDialog(BuildContext context) async {
|
|
try {
|
|
bool isLocationEnabled = await Geolocator.isLocationServiceEnabled();
|
|
LocationPermission permission = await Geolocator.checkPermission();
|
|
bool hasPermission = permission == LocationPermission.whileInUse ||
|
|
permission == LocationPermission.always;
|
|
|
|
if (!isLocationEnabled || !hasPermission) {
|
|
await showDialog(
|
|
// ignore: use_build_context_synchronously
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
return Dialog(
|
|
shape:
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
|
elevation: 10,
|
|
backgroundColor: Colors.white,
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
alignment: Alignment.topCenter,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
top: 40, left: 20, right: 20, bottom: 20),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const SizedBox(height: 10),
|
|
const Padding(
|
|
padding: EdgeInsets.all(15.0),
|
|
child: Text(
|
|
"فعالسازی موقعیت مکانی (GPS)",
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Text(
|
|
!isLocationEnabled
|
|
? "برای اینکه بتونیم تخفیفهای اطرافت رو سریع بهت اطلاع بدیم، لطفاً GPS رو فعال کن."
|
|
: "برای اینکه بتونیم تخفیفهای اطرافت رو سریع بهت اطلاع بدیم، اجازه بده به موقعیت مکانیت دسترسی داشته باشیم.",
|
|
style: const TextStyle(
|
|
color: AppColors.hint,
|
|
fontSize: 16,
|
|
),
|
|
textAlign: TextAlign.start,
|
|
),
|
|
const SizedBox(height: 20),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () => Navigator.of(context).pop(),
|
|
child: Text("الان نه",style: TextStyle(color: AppColors.primary,fontWeight: FontWeight.bold),),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColors.primary,
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
side: const BorderSide(color: AppColors.border),
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 45, vertical: 7),
|
|
),
|
|
onPressed: () async {
|
|
if (!isLocationEnabled) {
|
|
await Geolocator.openLocationSettings();
|
|
} else if (!hasPermission) {
|
|
await Geolocator.requestPermission();
|
|
}
|
|
// ignore: use_build_context_synchronously
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(
|
|
!isLocationEnabled ? "فعالسازی GPS" : "اجازه دسترسی",
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Positioned(
|
|
top: -40,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
// ignore: deprecated_member_use
|
|
color: Colors.black.withOpacity(0.3),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: CircleAvatar(
|
|
backgroundColor: Colors.white,
|
|
radius: 40,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: SvgPicture.asset(Assets.icons.globalSearch.path),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} catch (e) {
|
|
debugPrint("Error showing GPS dialog: $e");
|
|
}
|
|
} |