mnemo_cards/lib/pages/profile_page.dart

193 lines
7 KiB
Dart
Raw Normal View History

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';
2024-08-03 22:37:10 +00:00
import 'package:mnemo_cards/admin/add_plan.dart';
2024-08-24 21:09:58 +00:00
import 'package:mnemo_cards/admin/add_promocode_campaign.dart';
2024-05-22 20:48:44 +00:00
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-07-27 13:13:42 +00:00
import 'package:mnemo_cards/features/yandex_ads/yandex_ads.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-08-03 22:37:10 +00:00
import '../widgets/buy_subscription_widget.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;
2024-08-18 16:52:03 +00:00
int i = 0;
context.visitAncestorElements((visitor) {
if (visitor.widget.runtimeType == SizedBox) {
if ((visitor.widget as SizedBox).width == 200) {
print('found');
}
i++;
}
return true;
});
2024-05-22 20:48:44 +00:00
return Scaffold(
body: SafeArea(
child: Column(
children: [
2024-06-15 15:42:18 +00:00
Header(
2024-08-18 16:52:03 +00:00
'Профиль',
2024-06-15 15:42:18 +00:00
popText: 'назад',
hasPopButton: true,
trail: GestureDetector(
onTap: () async {
await locator.userManager.logout();
2024-08-24 21:09:58 +00:00
final showAdmin = SHOW_ADMIN;
2024-06-15 15:42:18 +00:00
final sp = await SharedPreferences.getInstance();
sp.clear();
2024-08-24 21:09:58 +00:00
if (showAdmin) {
globalSharedPreferences.setBool('show_admin', true);
}
2024-06-15 15:42:18 +00:00
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-08-24 21:09:58 +00:00
child: ListView(
physics: FixedExtentScrollPhysics(),
2024-05-22 20:48:44 +00:00
children: [
2024-08-24 21:09:58 +00:00
SizedBox(
height: 300.h,
2024-06-16 19:01:33 +00:00
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(
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),
),
2024-08-18 16:52:03 +00:00
const MobileBuySubscriptionWidget(),
2024-08-24 21:09:58 +00:00
Divider(
height: 5,
color: borderGray.withOpacity(0.2),
),
2024-08-06 21:33:11 +00:00
if (SHOW_ADMIN) ...[
SimpleTile(
title: Text('Посмотреть рекламу'),
onTap: () {
YandexAds.showRewardedAd((r) {
2024-08-18 16:52:03 +00:00
showInfoDialog(
2024-08-06 21:33:11 +00:00
'Вы получили\n${r.amount} ${r.type}');
});
},
),
Divider(
height: 5,
color: borderGray.withOpacity(0.2),
),
],
2024-06-16 19:01:33 +00:00
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();
}