mnemo_cards/lib/pages/profile_page.dart
2024-05-29 00:25:51 +03:00

210 lines
7.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:io';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mnemo_cards/domain/router/app_router.dart';
import 'package:mnemo_cards/flags.dart';
import 'package:mnemo_cards/widgets/header.dart';
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import '../admin/all_cards.dart';
import '../di/locator.dart';
import '../features/analytics/analytics.dart';
import '../theme/themes.dart';
import '../widgets/shared_pref_button.dart';
import '../widgets/text_button.dart';
@RoutePage()
class ProfilePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Analytics.profilePageOpened(locator.userManager.userStateHolder.user);
final theme = Theme.of(context).textTheme;
return Scaffold(
body: SafeArea(
child: Column(
children: [
StreamBuilder(
stream: locator.userManager.userStateHolder.asStream,
builder: (context, snapshot) {
var title = snapshot.data?.name;
if (true || title == null || title.length > 10) {
title = 'Привет!';
}
return Header(
title,
popText: 'назад',
hasPopButton: true,
trail: GestureDetector(
onTap: () async {
await locator.userManager.logout();
final sp = await SharedPreferences.getInstance();
sp.clear();
AppRouter.openAuthOrProfile();
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: [
Image.asset(
'icons/exit.png',
width: 25.w,
),
],
),
),
);
}),
SizedBox(
height: 40.h,
),
if (ADMIN_BUILD)
MaterialButton(
onPressed: () {
showDialog(
context: context, builder: (c) => const AllCards());
},
child: Text('ALL CARDS'),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0.w),
child: Text(
'Скоро тут будет прогресс, ачивки, настройки и другая важная информация',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Colors.black,
),
textAlign: TextAlign.center,
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0.w),
child: Text(
'А сейчас есть переключатель звука:',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Colors.black,
),
textAlign: TextAlign.center,
),
),
Expanded(
child: SharedPrefButton(
enabledWidget: Image.asset(
'icons/sound_on.png',
width: 140.w,
height: 120.h,
),
disabledWidget: Image.asset(
'icons/sound_off.png',
width: 140.w,
height: 120.h,
),
spKey: 'sound_on',
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0.w),
child: LinkButton(
'Написать в тг',
() => launchUrl(
Uri.parse('https://t.me/mnemo_cards_bot'),
),
),
),
SizedBox(
height: 30.0.h,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: LinkButton(
'Очистить кэш',
() async {
await locator.packManager.clearCache();
locator.testManager.clearStates();
await locator.packUpdater.updateAvailablePacks();
},
),
),
Flexible(
child: LinkButton(
'Страница в сторе',
() {},
),
),
],
),
),
SizedBox(
height: 30.0.h,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0.w),
child: LinkButton(
'Политика конфиденциальности',
() {
launchUrl(
Uri.parse(
'https://www.freeprivacypolicy.com/live/1c2bce51-86c6-4a36-b226-b6c6f50ebf0f'),
);
},
),
),
// Padding(
// padding: EdgeInsets.symmetric(horizontal: 10.0.w),
// child: LinkButton(
// 'Условия использования',
// () {
//
// },
// ),
// ),
Padding(
padding:
EdgeInsets.symmetric(horizontal: 10.0.w, vertical: 10.0.h),
child: InkWell(
onTap: AutoRouter.of(context).maybePop,
child: Container(
height: 90.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: borderGray),
borderRadius: BorderRadius.circular(16.0),
),
padding: EdgeInsets.all(10.0.w),
child: Text(
'Назад',
style: TextStyle(
fontSize: 25.sp,
fontWeight: FontWeight.w500,
height: 0.85,
),
),
),
),
),
],
),
),
);
}
Future<void> clearAndExit() async {
final sp = await SharedPreferences.getInstance();
sp.clear();
exit(0);
}
const ProfilePage();
}