2024-05-22 20:48:44 +00:00
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
|
import 'package:mnemo_cards/domain/router/app_router.dart';
|
2024-06-16 19:01:33 +00:00
|
|
|
|
import 'package:mnemo_cards/domain/router/app_router.gr.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
|
import 'package:mnemo_cards/flags.dart';
|
2024-06-16 19:01:33 +00:00
|
|
|
|
import 'package:mnemo_cards/main.dart';
|
2024-07-18 21:45:04 +00:00
|
|
|
|
import 'package:mnemo_cards_frontend_common/mnemo_cards_frontend_common.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../admin/all_cards.dart';
|
2024-05-29 14:26:44 +00:00
|
|
|
|
import '../admin/all_users.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
|
import '../di/locator.dart';
|
2024-07-22 20:49:30 +00:00
|
|
|
|
import '../domain/router/dialogs.dart';
|
2024-05-28 21:25:51 +00:00
|
|
|
|
import '../features/analytics/analytics.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
|
import '../theme/themes.dart';
|
2024-06-16 19:01:33 +00:00
|
|
|
|
import '../widgets/enter_promo_code_widget.dart';
|
2024-05-22 20:48:44 +00:00
|
|
|
|
import '../widgets/shared_pref_button.dart';
|
|
|
|
|
|
|
|
|
|
|
|
@RoutePage()
|
|
|
|
|
|
class ProfilePage extends StatelessWidget {
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-28 21:25:51 +00:00
|
|
|
|
Analytics.profilePageOpened(locator.userManager.userStateHolder.user);
|
2024-06-15 15:42:18 +00:00
|
|
|
|
locator.userManager.updateUser();
|
2024-05-22 20:48:44 +00:00
|
|
|
|
final theme = Theme.of(context).textTheme;
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
2024-06-15 15:42:18 +00:00
|
|
|
|
Header(
|
|
|
|
|
|
'Привет!',
|
|
|
|
|
|
popText: 'назад',
|
|
|
|
|
|
hasPopButton: true,
|
|
|
|
|
|
trail: GestureDetector(
|
|
|
|
|
|
onTap: () async {
|
|
|
|
|
|
await locator.userManager.logout();
|
|
|
|
|
|
final sp = await SharedPreferences.getInstance();
|
|
|
|
|
|
sp.clear();
|
|
|
|
|
|
AppRouter.openAuthOrProfile();
|
2024-05-29 14:26:44 +00:00
|
|
|
|
},
|
2024-06-15 15:42:18 +00:00
|
|
|
|
child: Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Image.asset(
|
|
|
|
|
|
'icons/exit.png',
|
|
|
|
|
|
width: 25.w,
|
2024-06-22 12:29:18 +00:00
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2024-06-15 15:42:18 +00:00
|
|
|
|
),
|
|
|
|
|
|
],
|
2024-05-22 20:48:44 +00:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
SizedBox(
|
|
|
|
|
|
height: 8.h,
|
|
|
|
|
|
),
|
2024-05-22 20:48:44 +00:00
|
|
|
|
Expanded(
|
2024-06-15 15:42:18 +00:00
|
|
|
|
child: Column(
|
2024-05-22 20:48:44 +00:00
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
|
children: [
|
2024-06-16 19:28:29 +00:00
|
|
|
|
if (SHOW_ADMIN)
|
2024-06-16 19:01:33 +00:00
|
|
|
|
Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: MaterialButton(
|
|
|
|
|
|
onPressed: () {
|
2024-07-25 10:07:11 +00:00
|
|
|
|
// showErrorDialog('Технические шоколадки...\n\nПопробуйте позже или обновите приложение до последней версии');
|
2024-07-22 20:49:30 +00:00
|
|
|
|
|
2024-07-25 10:07:11 +00:00
|
|
|
|
showDialog(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
builder: (c) => const AllCards());
|
2024-06-16 19:01:33 +00:00
|
|
|
|
},
|
|
|
|
|
|
child: Text('ALL CARDS'),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: MaterialButton(
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
showDialog(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
builder: (c) => const AllUsers());
|
|
|
|
|
|
},
|
|
|
|
|
|
child: Text('ALL USERS'),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2024-06-16 19:41:56 +00:00
|
|
|
|
if (SHOW_ADMIN)
|
|
|
|
|
|
Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
locator.packManager.clearCache();
|
|
|
|
|
|
},
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
|
margin: EdgeInsets.all(8.0),
|
|
|
|
|
|
child: Text('Clear cache'),
|
|
|
|
|
|
height: 40.h,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Expanded(
|
2024-07-18 21:45:04 +00:00
|
|
|
|
child: MobileSharedPrefButton<bool>(
|
2024-06-16 19:41:56 +00:00
|
|
|
|
builder: (v, _) =>
|
|
|
|
|
|
(v ?? false) ? Text('PROD') : Text('TEST'),
|
|
|
|
|
|
spKey: 'env',
|
|
|
|
|
|
setOnTap: (v) => !(v ?? false),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
Expanded(
|
|
|
|
|
|
child: StreamBuilder(
|
|
|
|
|
|
stream: locator.userManager.userStateHolder.asStream,
|
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
|
final userData = snapshot.data?.userDataDto;
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
|
|
left: 10.0,
|
|
|
|
|
|
right: 10.0,
|
|
|
|
|
|
bottom: 8.0,
|
|
|
|
|
|
),
|
|
|
|
|
|
child: UserStatistics(userData),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
2024-05-22 20:48:44 +00:00
|
|
|
|
),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Divider(
|
|
|
|
|
|
height: 5,
|
|
|
|
|
|
color: borderGray.withOpacity(0.2),
|
|
|
|
|
|
),
|
2024-07-18 21:45:04 +00:00
|
|
|
|
const MobileEnterPromoCodeWidget(),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
Divider(
|
|
|
|
|
|
height: 5,
|
|
|
|
|
|
color: borderGray.withOpacity(0.2),
|
|
|
|
|
|
),
|
|
|
|
|
|
SimpleTile.text(
|
|
|
|
|
|
text: 'Написать в телеграм',
|
|
|
|
|
|
onTap: () => launchUrl(
|
2024-06-15 15:42:18 +00:00
|
|
|
|
Uri.parse('https://t.me/mnemo_cards_bot'),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
Divider(
|
|
|
|
|
|
height: 5,
|
|
|
|
|
|
color: borderGray.withOpacity(0.2),
|
|
|
|
|
|
),
|
|
|
|
|
|
SimpleTile(
|
|
|
|
|
|
onTap: () => appRouter.push(
|
|
|
|
|
|
PageRouteInfo(SettingsPage.name),
|
|
|
|
|
|
),
|
|
|
|
|
|
title: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Image.asset(
|
|
|
|
|
|
'icons/settings.png',
|
|
|
|
|
|
width: 16.w,
|
2024-06-22 12:29:18 +00:00
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2024-06-16 19:01:33 +00:00
|
|
|
|
),
|
|
|
|
|
|
SizedBox(width: 8.w),
|
|
|
|
|
|
Expanded(child: Text('Настройки там')),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
trail: Image.asset(
|
|
|
|
|
|
'icons/next.png',
|
|
|
|
|
|
width: 16.w,
|
2024-06-22 12:29:18 +00:00
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2024-06-16 19:01:33 +00:00
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Divider(
|
|
|
|
|
|
height: 5,
|
|
|
|
|
|
color: borderGray.withOpacity(0.2),
|
2024-06-15 15:42:18 +00:00
|
|
|
|
),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
SizedBox(
|
|
|
|
|
|
height: 10.0.h,
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
2024-05-22 20:48:44 +00:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-06-16 19:01:33 +00:00
|
|
|
|
if (MediaQuery.of(context).viewInsets.bottom < 30.0)
|
|
|
|
|
|
const BigBackButton(),
|
2024-05-22 20:48:44 +00:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> clearAndExit() async {
|
|
|
|
|
|
final sp = await SharedPreferences.getInstance();
|
|
|
|
|
|
sp.clear();
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ProfilePage();
|
|
|
|
|
|
}
|