mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 18:35:28 +03:00
update
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class HapticService {
|
||||||
|
static const _key = 'haptic_enabled';
|
||||||
|
static bool _enabled = true; // runtime cache
|
||||||
|
|
||||||
|
static Future<void> init() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
_enabled = prefs.getBool(_key) ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool get isEnabled => _enabled;
|
||||||
|
|
||||||
|
static Future<void> setEnabled(bool value) async {
|
||||||
|
_enabled = value;
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setBool(_key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Light tap — filter chips, toggles, small interactions
|
||||||
|
static void light() {
|
||||||
|
if (!_enabled) return;
|
||||||
|
HapticFeedback.lightImpact();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Medium — confirm button, apply, save
|
||||||
|
static void medium() {
|
||||||
|
if (!_enabled) return;
|
||||||
|
HapticFeedback.mediumImpact();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Heavy — long press on balance card
|
||||||
|
static void heavy() {
|
||||||
|
if (!_enabled) return;
|
||||||
|
HapticFeedback.heavyImpact();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Selection click — switching tabs, filter chips
|
||||||
|
static void selection() {
|
||||||
|
if (!_enabled) return;
|
||||||
|
HapticFeedback.selectionClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
import '../../core/constants.dart';
|
import '../../core/constants.dart';
|
||||||
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../../shared/models/transaction.dart';
|
import '../../shared/models/transaction.dart';
|
||||||
import '../dashboard/provider.dart';
|
import '../dashboard/provider.dart';
|
||||||
import '../settings/provider.dart';
|
import '../settings/provider.dart';
|
||||||
@@ -159,6 +160,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
|
|
||||||
ref.read(addTransactionProvider(widget.initial).notifier).setSubmitting(false);
|
ref.read(addTransactionProvider(widget.initial).notifier).setSubmitting(false);
|
||||||
|
|
||||||
|
HapticService.medium();
|
||||||
|
|
||||||
if (mounted) context.pop();
|
if (mounted) context.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import 'package:intl/intl.dart';
|
|||||||
import 'package:sensors_plus/sensors_plus.dart';
|
import 'package:sensors_plus/sensors_plus.dart';
|
||||||
import '../../core/constants.dart';
|
import '../../core/constants.dart';
|
||||||
import '../../core/services/card_color_service.dart';
|
import '../../core/services/card_color_service.dart';
|
||||||
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../../shared/models/transaction.dart';
|
import '../../shared/models/transaction.dart';
|
||||||
import '../../shared/utils/currency_utils.dart';
|
import '../../shared/utils/currency_utils.dart';
|
||||||
import '../../shared/providers/amount_format_provider.dart';
|
import '../../shared/providers/amount_format_provider.dart';
|
||||||
@@ -108,6 +109,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
|
|
||||||
void _closeOverlay({required bool apply}) {
|
void _closeOverlay({required bool apply}) {
|
||||||
if (apply) {
|
if (apply) {
|
||||||
|
HapticService.medium();
|
||||||
ref.read(cardColorsProvider.notifier).save(_tempPrimary, _tempSecondary, _tempGradientType);
|
ref.read(cardColorsProvider.notifier).save(_tempPrimary, _tempSecondary, _tempGradientType);
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -191,7 +193,10 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
onPressed: () => context.push('/add'),
|
onPressed: () {
|
||||||
|
HapticService.medium();
|
||||||
|
context.push('/add');
|
||||||
|
},
|
||||||
backgroundColor: const Color(0xFF7C6DED),
|
backgroundColor: const Color(0xFF7C6DED),
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
icon: const Icon(Icons.add),
|
icon: const Icon(Icons.add),
|
||||||
@@ -486,7 +491,10 @@ class _FilterChip extends StatelessWidget {
|
|||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: onTap,
|
onTap: () {
|
||||||
|
HapticService.selection();
|
||||||
|
onTap();
|
||||||
|
},
|
||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||||
@@ -745,7 +753,10 @@ class _BalanceCardState extends ConsumerState<_BalanceCard>
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onLongPress: widget.onLongPress,
|
onLongPress: () {
|
||||||
|
HapticService.heavy();
|
||||||
|
widget.onLongPress?.call();
|
||||||
|
},
|
||||||
child: AnimatedBuilder(
|
child: AnimatedBuilder(
|
||||||
animation: _controller,
|
animation: _controller,
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import '../../core/constants.dart';
|
import '../../core/constants.dart';
|
||||||
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../../shared/services/exchange_rate_service.dart';
|
import '../../shared/services/exchange_rate_service.dart';
|
||||||
import '../../shared/utils/currency_utils.dart';
|
import '../../shared/utils/currency_utils.dart';
|
||||||
import '../../shared/providers/amount_format_provider.dart';
|
import '../../shared/providers/amount_format_provider.dart';
|
||||||
@@ -103,6 +105,27 @@ final ratesInitProvider = FutureProvider<void>((ref) async {
|
|||||||
await ref.read(exchangeRateServiceProvider).fetchRates();
|
await ref.read(exchangeRateServiceProvider).fetchRates();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final hapticEnabledProvider = StateNotifierProvider<HapticNotifier, bool>((ref) {
|
||||||
|
return HapticNotifier();
|
||||||
|
});
|
||||||
|
|
||||||
|
class HapticNotifier extends StateNotifier<bool> {
|
||||||
|
HapticNotifier() : super(true) {
|
||||||
|
_load();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _load() async {
|
||||||
|
state = HapticService.isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> toggle(bool value) async {
|
||||||
|
await HapticService.setEnabled(value);
|
||||||
|
state = value;
|
||||||
|
// Give tactile confirmation when turning ON
|
||||||
|
if (value) HapticFeedback.mediumImpact();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final exportProvider = Provider<ExportService>((ref) {
|
final exportProvider = Provider<ExportService>((ref) {
|
||||||
return ExportService(ref);
|
return ExportService(ref);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import '../../core/constants.dart';
|
import '../../core/constants.dart';
|
||||||
import '../../core/services/biometric_service.dart';
|
import '../../core/services/biometric_service.dart';
|
||||||
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../../shared/utils/currency_utils.dart';
|
import '../../shared/utils/currency_utils.dart';
|
||||||
import '../../shared/providers/amount_format_provider.dart';
|
import '../../shared/providers/amount_format_provider.dart';
|
||||||
import '../dashboard/provider.dart';
|
import '../dashboard/provider.dart';
|
||||||
@@ -191,6 +192,64 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
Consumer(
|
||||||
|
builder: (context, ref, _) {
|
||||||
|
final enabled = ref.watch(hapticEnabledProvider);
|
||||||
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
border: isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.accent.withOpacity(0.15),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.vibration_rounded,
|
||||||
|
color: AppColors.accent,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Haptic Feedback',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'Vibration on interactions',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Switch(
|
||||||
|
value: enabled,
|
||||||
|
onChanged: (val) => ref.read(hapticEnabledProvider.notifier).toggle(val),
|
||||||
|
activeColor: const Color(0xFF7C6DED),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
const _BiometricSection(),
|
const _BiometricSection(),
|
||||||
|
|
||||||
Container(
|
Container(
|
||||||
@@ -584,6 +643,7 @@ class _BiometricSectionState extends State<_BiometricSection> {
|
|||||||
if (val) {
|
if (val) {
|
||||||
final ok = await BiometricService.authenticate();
|
final ok = await BiometricService.authenticate();
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
HapticService.light();
|
||||||
}
|
}
|
||||||
await BiometricService.setEnabled(val);
|
await BiometricService.setEnabled(val);
|
||||||
if (mounted) setState(() => _enabled = val);
|
if (mounted) setState(() => _enabled = val);
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'app/app.dart';
|
import 'app/app.dart';
|
||||||
|
import 'core/services/haptic_service.dart';
|
||||||
import 'features/dashboard/provider.dart';
|
import 'features/dashboard/provider.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await HapticService.init();
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
ProviderScope(
|
ProviderScope(
|
||||||
|
|||||||
Reference in New Issue
Block a user