You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.0 KiB
151 lines
5.0 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart';
|
|
import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart';
|
|
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart';
|
|
import 'package:hadi_hoda_flutter/core/routers/my_routes.dart';
|
|
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart';
|
|
import 'package:hadi_hoda_flutter/core/utils/my_localization.dart';
|
|
import 'package:hadi_hoda_flutter/core/utils/screen_size.dart';
|
|
import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart';
|
|
import 'package:hadi_hoda_flutter/core/widgets/animations/slide_down_fade.dart';
|
|
import 'package:hadi_hoda_flutter/core/widgets/animations/slide_up_fade.dart';
|
|
import 'package:hadi_hoda_flutter/core/widgets/button/my_yellow_button.dart';
|
|
import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
|
|
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
|
|
import 'package:hadi_hoda_flutter/core/widgets/pop_scope/my_pop_scope.dart';
|
|
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart';
|
|
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_bloc.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_checkFirstBatch();
|
|
});
|
|
}
|
|
|
|
void _checkFirstBatch() async {
|
|
if (!mounted) return;
|
|
final bloc = context.read<HomeBloc>();
|
|
final lastDownloadLevel = await bloc.getLastDownloadedLevel();
|
|
if (lastDownloadLevel < MyConstants.firstDownloadBatchCount && mounted) {
|
|
context.goNamed(
|
|
Routes.downloadPage,
|
|
extra: const DownloadPageConfig(
|
|
downloadToLevel: MyConstants.firstDownloadBatchCount,
|
|
redirectTo: Routes.homePage,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: MyPopScope(
|
|
child: DecoratedBox(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(MyAssets.backgroundHome),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
child: SizedBox.expand(
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
_music(context),
|
|
_image(context),
|
|
_bottomBtns(context),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _music(BuildContext context) {
|
|
return PositionedDirectional(
|
|
top: setPlatform(android: MySpaces.s36, iOS: 50),
|
|
end: MySpaces.s16,
|
|
child: SlideDownFade(
|
|
delay: const Duration(milliseconds: 100),
|
|
child: StreamBuilder<double>(
|
|
initialData: 1,
|
|
stream: context.read<HomeBloc>().volumeStream,
|
|
builder: (context, snapshot) => MyInkwell(
|
|
onTap: () => context.read<HomeBloc>().changeMute(),
|
|
child: MyImage(
|
|
image: snapshot.data == 0 ? MyAssets.musicOff : MyAssets.musicOn,
|
|
size: setSize(context: context, tablet: 100),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Positioned _image(BuildContext context) {
|
|
return Positioned(
|
|
top: setSize(context: context, mobile: 0.1.h, tablet: 0.15.h),
|
|
child: const Stack(
|
|
children: [
|
|
MyImage(image: MyAssets.hadiHoda),
|
|
PositionedDirectional(
|
|
start: MySpaces.s10,
|
|
top: MySpaces.s40,
|
|
child: MyImage(image: MyAssets.globe),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Positioned _bottomBtns(BuildContext context) {
|
|
return Positioned(
|
|
bottom: setPlatform(android: MySpaces.s40, iOS: MySpaces.s0),
|
|
left: MySpaces.s16,
|
|
right: MySpaces.s16,
|
|
child: SafeArea(
|
|
child: SlideUpFade(
|
|
delay: const Duration(milliseconds: 100),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
MyInkwell(
|
|
onTap: () => context.read<HomeBloc>().goToLanguagePage(context),
|
|
child: MyImage(
|
|
image: MyAssets.language,
|
|
size: setSize(context: context, tablet: 100),
|
|
),
|
|
),
|
|
MyYellowButton(
|
|
onTap: () => context.read<HomeBloc>().goToLevelPage(context),
|
|
title: context.translate.start,
|
|
),
|
|
MyInkwell(
|
|
onTap: () => context.read<HomeBloc>().showAboutUs(context),
|
|
child: MyImage(
|
|
image: MyAssets.theme,
|
|
size: setSize(context: context, tablet: 100),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|