feat: add haptic feedback (#1459)

Co-authored-by: Ushie <ushiekane@gmail.com>
Co-authored-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
Benjamin
2024-01-14 14:29:24 -08:00
committed by GitHub
parent ef9b1d5c2d
commit 7911459817
21 changed files with 236 additions and 19 deletions

View File

@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HapticCheckbox extends StatelessWidget {
const HapticCheckbox({
super.key,
required this.value,
required this.onChanged,
this.activeColor,
this.checkColor,
this.side,
});
final bool value;
final Function(bool?)? onChanged;
final Color? activeColor;
final Color? checkColor;
final BorderSide? side;
@override
Widget build(BuildContext context) {
return Checkbox(
value: value,
onChanged: (value) => {
HapticFeedback.selectionClick(),
if (onChanged != null) onChanged!(value),
},
activeColor: activeColor,
checkColor: checkColor,
side: side,
);
}
}

View File

@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HapticCheckboxListTile extends StatelessWidget {
const HapticCheckboxListTile({
super.key,
required this.value,
required this.onChanged,
this.title,
this.subtitle,
this.contentPadding,
});
final bool value;
final Function(bool?)? onChanged;
final Widget? title;
final Widget? subtitle;
final EdgeInsetsGeometry? contentPadding;
@override
Widget build(BuildContext context) {
return CheckboxListTile(
contentPadding: contentPadding ?? EdgeInsets.zero,
title: title,
subtitle: subtitle,
value: value,
onChanged: (value) => {
HapticFeedback.lightImpact(),
if (onChanged != null) onChanged!(value),
},
);
}
}

View File

@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
class HapticCustomCard extends StatelessWidget {
const HapticCustomCard({
super.key,
this.isFilled = true,
required this.child,
this.onTap,
this.padding,
this.backgroundColor,
});
final bool isFilled;
final Widget child;
final Function()? onTap;
final EdgeInsetsGeometry? padding;
final Color? backgroundColor;
@override
Widget build(BuildContext context) {
return CustomCard(
isFilled: isFilled,
onTap: () => {
HapticFeedback.selectionClick(),
if (onTap != null) onTap!(),
},
padding: padding,
backgroundColor: backgroundColor,
child: child,
);
}
}

View File

@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HapticFloatingActionButtonExtended extends StatelessWidget {
const HapticFloatingActionButtonExtended({
super.key,
required this.onPressed,
required this.label,
this.icon,
this.elevation,
});
final Function()? onPressed;
final Widget label;
final Widget? icon;
final double? elevation;
@override
Widget build(BuildContext context) {
return FloatingActionButton.extended(
onPressed: () => {
HapticFeedback.lightImpact(),
if (onPressed != null) onPressed!(),
},
label: label,
icon: icon,
elevation: elevation,
);
}
}

View File

@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HapticRadioListTile extends StatelessWidget {
const HapticRadioListTile({
super.key,
required this.title,
required this.value,
required this.groupValue,
this.subtitle,
this.onChanged,
this.contentPadding,
});
final Widget title;
final Widget? subtitle;
final int value;
final Function(int?)? onChanged;
final int groupValue;
final EdgeInsetsGeometry? contentPadding;
@override
Widget build(BuildContext context) {
return RadioListTile(
contentPadding: contentPadding ?? EdgeInsets.zero,
title: title,
subtitle: subtitle,
value: value,
groupValue: groupValue,
onChanged: (val) => {
if (val == value) {
HapticFeedback.lightImpact(),
},
if (onChanged != null) onChanged!(val),
},
);
}
}

View File

@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HapticSwitchListTile extends StatelessWidget {
const HapticSwitchListTile({
super.key,
required this.value,
required this.onChanged,
this.title,
this.subtitle,
this.contentPadding,
});
final bool value;
final Function(bool)? onChanged;
final Widget? title;
final Widget? subtitle;
final EdgeInsetsGeometry? contentPadding;
@override
Widget build(BuildContext context) {
return SwitchListTile(
contentPadding: contentPadding ?? EdgeInsets.zero,
title: title,
subtitle: subtitle,
value: value,
onChanged: (value) => {
if (value) {
HapticFeedback.mediumImpact(),
} else {
HapticFeedback.lightImpact(),
},
if (onChanged != null) onChanged!(value),
},
);
}
}