116 lines
3.6 KiB
Dart
116 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import '../../../core/l10n/app_localizations.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../core/design/tokens.dart';
|
|
import '../../../core/ui/tripz_button.dart';
|
|
import '../bloc/trip_bloc.dart';
|
|
import '../bloc/trip_state.dart';
|
|
import '../bloc/trip_event.dart';
|
|
|
|
/// شاشة تقييم الرحلة.
|
|
class RatingScreen extends StatefulWidget {
|
|
const RatingScreen({super.key});
|
|
|
|
@override
|
|
State<RatingScreen> createState() => _RatingScreenState();
|
|
}
|
|
|
|
class _RatingScreenState extends State<RatingScreen> {
|
|
int _stars = 0;
|
|
final _commentController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_commentController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return BlocListener<TripBloc, TripState>(
|
|
listenWhen: (prev, cur) => prev.rated != cur.rated,
|
|
listener: (context, state) {
|
|
if (state.rated) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(l10n.thankYou)),
|
|
);
|
|
context.read<TripBloc>().add(const TripClear());
|
|
context.go('/home');
|
|
}
|
|
},
|
|
child: Scaffold(
|
|
appBar: AppBar(title: Text(l10n.rateYourTrip)),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(T.pagePadding),
|
|
child: Column(
|
|
children: [
|
|
const Spacer(flex: 2),
|
|
|
|
// نجوم التقييم
|
|
Text(
|
|
l10n.rateDriver,
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
const SizedBox(height: T.s24),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: List.generate(5, (i) {
|
|
final index = i + 1;
|
|
return GestureDetector(
|
|
onTap: () => setState(() => _stars = index),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 6),
|
|
child: Icon(
|
|
index <= _stars ? Icons.star_rounded : Icons.star_outline_rounded,
|
|
size: 48,
|
|
color: index <= _stars ? Colors.amber : cs.onSurfaceVariant,
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
|
|
const SizedBox(height: T.s24),
|
|
|
|
// حقل التعليق
|
|
TextField(
|
|
controller: _commentController,
|
|
maxLines: 3,
|
|
decoration: InputDecoration(
|
|
hintText: l10n.ratingComment,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
),
|
|
|
|
const Spacer(flex: 3),
|
|
|
|
// زر الإرسال
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: TripzButton(
|
|
label: l10n.submitRating,
|
|
onPressed: _stars > 0
|
|
? () {
|
|
context.read<TripBloc>().add(TripRate(
|
|
stars: _stars,
|
|
comment: _commentController.text,
|
|
));
|
|
}
|
|
: null,
|
|
),
|
|
),
|
|
const SizedBox(height: T.s8),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|