2024-01-01 18:31:10 +01:00
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
import '../../../utils/logic/preferences_service.dart'; // For HapticFeedback
|
2024-01-01 18:31:10 +01:00
|
|
|
|
|
|
|
// ...Include PreferencesService and other necessary imports
|
|
|
|
|
|
|
|
class SetPinPopup extends StatefulWidget {
|
2024-01-09 12:34:44 +01:00
|
|
|
const SetPinPopup({super.key});
|
|
|
|
|
2024-01-01 18:31:10 +01:00
|
|
|
@override
|
2024-01-09 12:34:44 +01:00
|
|
|
State<SetPinPopup> createState() => _SetPinPopup();
|
2024-01-01 18:31:10 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
class _SetPinPopup extends State<SetPinPopup> {
|
2024-01-01 18:31:10 +01:00
|
|
|
String _pin = '';
|
|
|
|
String _confirmedPin = '';
|
2024-01-09 12:34:44 +01:00
|
|
|
bool _isSettingPin = true; // True if setting the PIN, false if confirming the PIN
|
2024-01-01 18:31:10 +01:00
|
|
|
|
|
|
|
static const int pinLength = 4;
|
|
|
|
|
|
|
|
// Include the methods from PinInputScreen here
|
|
|
|
List<Widget> _buildNumberPad() {
|
|
|
|
List<int> numbers = List.generate(9, (index) => index + 1);
|
|
|
|
List<Widget> rows = [];
|
|
|
|
|
|
|
|
// First three rows (1-9)
|
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
|
rows.add(
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: numbers.skip(i * 3).take(3).map((number) {
|
|
|
|
return _buildNumberButton(number);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last row with 0
|
|
|
|
rows.add(
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Container(width: 70), // Empty container to align 0 in center
|
|
|
|
_buildNumberButton(0),
|
|
|
|
Container(width: 70), // Empty container to align 0 in center
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildNumberButton(int number) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () => _onNumberTap(number),
|
2024-01-09 12:34:44 +01:00
|
|
|
onTapDown: (_) => HapticFeedback.lightImpact(), // Cool haptic feedback on tap
|
2024-01-01 18:31:10 +01:00
|
|
|
child: Container(
|
|
|
|
width: 70,
|
|
|
|
height: 70,
|
2024-01-09 12:34:44 +01:00
|
|
|
margin: const EdgeInsets.all(10),
|
2024-01-01 18:31:10 +01:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(color: Colors.black),
|
|
|
|
borderRadius: BorderRadius.circular(35),
|
|
|
|
),
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
number.toString(),
|
2024-01-09 12:34:44 +01:00
|
|
|
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
2024-01-01 18:31:10 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onNumberTap(int number) {
|
|
|
|
setState(() {
|
|
|
|
if (_isSettingPin) {
|
|
|
|
_pin += number.toString();
|
|
|
|
} else {
|
|
|
|
_confirmedPin += number.toString();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
if ((_isSettingPin && _pin.length == pinLength) || (!_isSettingPin && _confirmedPin.length == pinLength)) {
|
2024-01-01 18:31:10 +01:00
|
|
|
if (!_isSettingPin && _pin == _confirmedPin) {
|
|
|
|
// Call setPin and enablePin methods, assuming they are async
|
|
|
|
PreferencesService().setPin(int.parse(_pin));
|
|
|
|
PreferencesService().enablePin();
|
|
|
|
Navigator.of(context).pop(); // Close the dialog
|
|
|
|
} else if (!_isSettingPin && _pin != _confirmedPin) {
|
|
|
|
// PINs don't match, reset and let the user set the PIN again
|
|
|
|
setState(() {
|
|
|
|
_pin = '';
|
|
|
|
_confirmedPin = '';
|
|
|
|
_isSettingPin = true; // Reset back to setting PIN
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Move to confirming the PIN
|
|
|
|
setState(() {
|
|
|
|
_isSettingPin = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Dialog(
|
2024-01-13 17:07:11 +01:00
|
|
|
shadowColor: Colors.white,
|
2024-01-01 18:31:10 +01:00
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
child: BackdropFilter(
|
2024-01-13 17:07:11 +01:00
|
|
|
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 15, tileMode: TileMode.repeated),
|
2024-01-01 18:31:10 +01:00
|
|
|
child: Container(
|
|
|
|
height: 600,
|
|
|
|
width: 400,
|
2024-01-09 12:34:44 +01:00
|
|
|
decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(50))),
|
2024-01-01 18:31:10 +01:00
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2024-01-09 12:34:44 +01:00
|
|
|
Text(_isSettingPin ? 'Set a PIN' : 'Repeat PIN', style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
|
|
|
|
const SizedBox(height: 20),
|
2024-01-01 18:31:10 +01:00
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: List.generate(pinLength, (index) {
|
|
|
|
return Container(
|
2024-01-09 12:34:44 +01:00
|
|
|
margin: const EdgeInsets.all(4),
|
2024-01-01 18:31:10 +01:00
|
|
|
width: 15,
|
|
|
|
height: 15,
|
|
|
|
decoration: BoxDecoration(
|
2024-01-13 17:07:11 +01:00
|
|
|
color: (_isSettingPin ? _pin.length : _confirmedPin.length) > index ? const Color(0xffD9D9D9) : Colors.transparent,
|
|
|
|
border: Border.all(color: const Color(0xffD9D9D9)),
|
2024-01-01 18:31:10 +01:00
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
2024-01-09 12:34:44 +01:00
|
|
|
const SizedBox(height: 20),
|
2024-01-01 18:31:10 +01:00
|
|
|
..._buildNumberPad(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|