Files
kmobile/lib/widgets/tnc_dialog.dart
2025-11-09 15:42:50 +05:30

92 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:kmobile/features/auth/screens/tnc_required_screen.dart';
class TncDialog extends StatefulWidget {
// Add a callback function for when the user proceeds
final Future<void> Function() onProceed;
const TncDialog({Key? key, required this.onProceed}) : super(key: key);
@override
_TncDialogState createState() => _TncDialogState();
}
class _TncDialogState extends State<TncDialog> {
bool _isAgreed = false;
bool _isLoading = false;
void _handleProceed() async {
if (_isLoading) return;
setState(() {
_isLoading = true;
});
// Call the provided onProceed function, which will trigger the cubit
await widget.onProceed();
// The dialog will be dismissed by the navigation that happens in the BlocListener
// so we don't need to pop here. If for some reason it's still visible,
// we can add a mounted check and pop.
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Terms and Conditions'),
content: SingleChildScrollView(
child: _isLoading
? const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircularProgressIndicator(),
),
)
: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Please read and accept our terms and conditions to continue. '
'This is a placeholder for the actual terms and conditions text.'),
const SizedBox(height: 16),
Row(
children: [
Checkbox(
value: _isAgreed,
onChanged: (bool? value) {
setState(() {
_isAgreed = value ?? false;
});
},
),
const Flexible(
child: Text('I agree to the Terms and Conditions')),
],
),
],
),
),
actions: [
TextButton(
// Disable button while loading
onPressed: _isLoading ? null : () {
// Pop with false to indicate disagreement
Navigator.of(context).pop(false);
},
child: const Text('Disagree'),
),
ElevatedButton(
// Disable button if not agreed or while loading
onPressed: _isAgreed && !_isLoading ? _handleProceed : null,
child: const Text('Proceed'),
),
],
);
}
}