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 '../admin/all_users.dart'; import '../di/locator.dart'; import '../features/analytics/analytics.dart'; import '../theme/themes.dart'; import '../widgets/big_back_button.dart'; import '../widgets/shared_pref_button.dart'; import '../widgets/simple_tile.dart'; import '../widgets/slider.dart'; import '../widgets/switch_button.dart'; import '../widgets/switch_tile.dart'; import '../widgets/text_button.dart'; import '../widgets/user_statistics.dart'; @RoutePage() class ProfilePage extends StatelessWidget { @override Widget build(BuildContext context) { Analytics.profilePageOpened(locator.userManager.userStateHolder.user); locator.userManager.updateUser(); final theme = Theme.of(context).textTheme; return Scaffold( body: SafeArea( child: Column( children: [ Header( 'Привет!', 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, ), ], ), ), ), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ StreamBuilder( stream: locator.userManager.userStateHolder.asStream, builder: (context, snapshot) { final userData = snapshot.data?.userDataDto; return Column( children: [ if (ADMIN_BUILD) MaterialButton( onPressed: () { showDialog( context: context, builder: (c) => const AllCards()); }, child: Text('ALL CARDS'), ), if (ADMIN_BUILD) MaterialButton( onPressed: () { showDialog( context: context, builder: (c) => const AllUsers()); }, child: Text('ALL USERS'), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 10.0), child: Column( children: [ Padding( padding: const EdgeInsets.only(bottom: 8.0), child: UserStatistics(userData), ), SharedPrefButton.builder( spKey: 'sound_on', builder: (enabled, _) => AbsorbPointer( child: SwitchTile( text: 'Звук', value: enabled ?? false, ), ), setOnTap: (v) => !(v ?? false), ), Divider( height: 1, color: borderGray.withOpacity(0.2), ), SharedPrefButton.builder( spKey: 'auto_play_sound', builder: (enabled, _) => AbsorbPointer( child: SwitchTile( text: 'Авто воспроизведение в тестах', value: enabled ?? false, ), ), setOnTap: (v) => !(v ?? false), ), Divider( height: 5, color: borderGray.withOpacity(0.2), ), SimpleTile( text: 'Скорость чтения', trail: SharedPrefButton.builder( spKey: 'sound_speed', builder: (v, s) => MnemoSlider( onChanged: (value) => s(value), value: v ?? 1.0, ), shouldRebuild: (v) => false, ), ), ], ), ) ], ); }, ), Column( mainAxisSize: MainAxisSize.min, children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 10.0.w), child: LinkButton( 'Написать в тг', () => launchUrl( Uri.parse('https://t.me/mnemo_cards_bot'), ), ), ), SizedBox( height: 10.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'), ); }, ), ), ], ), ], ), ), const BigBackButton(), ], ), ), ); } Future clearAndExit() async { final sp = await SharedPreferences.getInstance(); sp.clear(); exit(0); } const ProfilePage(); }