Browse Source

add: inkwell with play audio effect

pull/31/head
AmirrezaChegini 18 hours ago
parent
commit
4b30d1fa07
  1. 5
      lib/core/widgets/button/my_blue_button.dart
  2. 3
      lib/core/widgets/button/my_yellow_button.dart
  3. 4
      lib/core/widgets/dialog/about_us_dialog.dart
  4. 3
      lib/core/widgets/dialog/styles/dialog_button.dart
  5. 55
      lib/core/widgets/inkwell/my_inkwell.dart
  6. 9
      lib/features/home/presentation/bloc/home_bloc.dart
  7. 7
      lib/features/home/presentation/ui/home_page.dart

5
lib/core/widgets/button/my_blue_button.dart

@ -5,6 +5,7 @@ import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart';
import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart';
import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart';
import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
class MyBlueButton extends StatelessWidget {
const MyBlueButton({
@ -20,7 +21,7 @@ class MyBlueButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
return MyInkwell(
onTap: onTap,
highlightColor: MyColors.transparent,
splashColor: MyColors.transparent,
@ -36,7 +37,7 @@ class MyBlueButton extends StatelessWidget {
'',
),
PositionedDirectional(
top: top ?? setSize(context: context, mobile: MySpaces.s10, tablet: MySpaces.s20),
top: top ?? setSize(context: context, mobile: MySpaces.s6, tablet: MySpaces.s20),
child: Text(
title ?? '',
style: MYTextStyle.button1.copyWith(

3
lib/core/widgets/button/my_yellow_button.dart

@ -5,6 +5,7 @@ import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart';
import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart';
import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart';
import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
class MyYellowButton extends StatelessWidget {
const MyYellowButton({
@ -20,7 +21,7 @@ class MyYellowButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
return MyInkwell(
onTap: onTap,
highlightColor: MyColors.transparent,
splashColor: MyColors.transparent,

4
lib/core/widgets/dialog/about_us_dialog.dart

@ -9,6 +9,7 @@ import 'package:hadi_hoda_flutter/core/utils/my_localization.dart';
import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart';
import 'package:hadi_hoda_flutter/core/widgets/dialog/styles/dialog_background.dart';
import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
Future<void> showAboutUsDialog({required BuildContext context}) async {
await showDialog(
@ -91,9 +92,8 @@ class AboutUsDialog extends StatelessWidget {
Positioned(
right: setSize(context: context, mobile: 30, tablet: 40),
top: setSize(context: context, mobile: -12, tablet: -20),
child: GestureDetector(
child: MyInkwell(
onTap: context.pop,
behavior: HitTestBehavior.opaque,
child: MyImage(
image: MyAssets.closeBtn,
size: setSize(context: context, mobile: 40, tablet: 60),

3
lib/core/widgets/dialog/styles/dialog_button.dart

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
class DialogButton extends StatelessWidget {
const DialogButton({
@ -20,7 +21,7 @@ class DialogButton extends StatelessWidget {
clipper: ButtonDialogClipper(),
child: Material(
type: MaterialType.transparency,
child: InkWell(
child: MyInkwell(
onTap: onTap,
child: Ink(
height: height,

55
lib/core/widgets/inkwell/my_inkwell.dart

@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
import 'package:hadi_hoda_flutter/common_ui/resources/my_audios.dart';
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart';
import 'package:hadi_hoda_flutter/core/services/audio_service.dart';
import 'package:hadi_hoda_flutter/init_bindings.dart';
class MyInkwell extends StatefulWidget {
const MyInkwell({
super.key,
this.onTap,
this.child,
this.borderRadius,
this.highlightColor,
this.splashColor,
});
final VoidCallback? onTap;
final Widget? child;
final BorderRadius? borderRadius;
final Color? highlightColor;
final Color? splashColor;
@override
State<MyInkwell> createState() => _MyInkwellState();
}
class _MyInkwellState extends State<MyInkwell> {
final AudioService audioService = locator(
instanceName: MyConstants.effectAudioService,
);
@override
void initState() {
super.initState();
}
void playAudio() {
audioService.setAudio(assetPath: MyAudios.clickButton);
audioService.play();
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
playAudio();
widget.onTap?.call();
},
borderRadius: widget.borderRadius,
highlightColor: widget.highlightColor,
splashColor: widget.splashColor,
child: widget.child,
);
}
}

9
lib/features/home/presentation/bloc/home_bloc.dart

@ -38,7 +38,6 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
/// ------------Functions------------
void goToLevelPage(BuildContext context){
playEffect();
final String? selectedLanguage = LocalStorage.readData(key: MyConstants.selectLanguage);
final Box<TotalDataEntity> dataBox = Hive.box(MyConstants.levelBox);
final TotalDataEntity findData = dataBox.values.singleWhere(
@ -53,17 +52,14 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
}
void goToLanguagePage(BuildContext context){
playEffect();
context.pushNamed(Routes.languagePage);
}
void showAboutUs(BuildContext context){
playEffect();
showAboutUsDialog(context: context);
}
Future<void> changeMute() async {
playEffect();
await Future.wait([
_mainAudioService.changeMute(),
_effectAudioService.changeMute(),
@ -78,11 +74,6 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
await _mainAudioService.play();
}
Future<void> playEffect() async{
await _effectAudioService.setAudio(assetPath: MyAudios.clickButton);
await _effectAudioService.play();
}
void onPopInvokedWithResult(bool didPop, dynamic result) {
showExitDialog(context: ContextProvider.context);
}

7
lib/features/home/presentation/ui/home_page.dart

@ -7,6 +7,7 @@ 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/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/features/home/presentation/bloc/home_bloc.dart';
class HomePage extends StatelessWidget {
@ -49,7 +50,7 @@ class HomePage extends StatelessWidget {
child: StreamBuilder<double>(
initialData: 1,
stream: context.read<HomeBloc>().volumeStream,
builder: (context, snapshot) => InkWell(
builder: (context, snapshot) => MyInkwell(
onTap: () => context.read<HomeBloc>().changeMute(),
child: MyImage(
image: snapshot.data == 0 ? MyAssets.musicOff : MyAssets.musicOn,
@ -90,7 +91,7 @@ class HomePage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
MyInkwell(
onTap: () => context.read<HomeBloc>().goToLanguagePage(context),
child: MyImage(
image: MyAssets.language,
@ -101,7 +102,7 @@ class HomePage extends StatelessWidget {
onTap: () => context.read<HomeBloc>().goToLevelPage(context),
title: context.translate.start,
),
InkWell(
MyInkwell(
onTap: () => context.read<HomeBloc>().showAboutUs(context),
child: MyImage(
image: MyAssets.theme,

Loading…
Cancel
Save