207 lines
5.9 KiB
Dart
207 lines
5.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
import 'package:readmore/readmore.dart';
|
|
import 'package:remever/common/functions.dart';
|
|
import 'package:remever/common/resources.dart';
|
|
import 'package:remever/common/typography.dart';
|
|
import 'package:remever/common/widgets/w_if.dart';
|
|
import 'package:remever/common/widgets/wspace.dart';
|
|
import 'package:remever/components/extensions/context.dart';
|
|
import 'package:remever/components/extensions/state.dart';
|
|
import 'package:remever/database/database.dart';
|
|
import 'package:remever/gen/assets.gen.dart';
|
|
import 'package:remever/inject.dart';
|
|
import 'package:remever/screens/dialogs/alert_dialog.dart';
|
|
import 'package:remever/screens/dialogs/replace_diaog.dart';
|
|
import 'package:remever/services/tickets/tickets_interface.dart';
|
|
|
|
class TicketCard extends StatefulWidget {
|
|
const TicketCard({
|
|
required this.ticket,
|
|
required this.currentCollection,
|
|
super.key,
|
|
});
|
|
|
|
final Collection currentCollection;
|
|
final Ticket ticket;
|
|
|
|
@override
|
|
State<TicketCard> createState() => _TicketCardState();
|
|
}
|
|
|
|
class _TicketCardState extends State<TicketCard> {
|
|
bool _isRolled = false;
|
|
|
|
void _onDeleteTap() async {
|
|
final bool? res = await showCuperModalBottomSheet(
|
|
context: context,
|
|
height: 262.h,
|
|
builder:
|
|
(_) => const AlertInfoDialog(
|
|
title: 'Вы хотите удалить карточку?\nЭто действие необратимо',
|
|
acceptTitle: 'Да, удалить',
|
|
declineTitle: 'Нет, оставить',
|
|
),
|
|
);
|
|
|
|
if (res != null && res) {
|
|
await getIt<TicketsInterface>().removeTicket(widget.ticket.id);
|
|
}
|
|
}
|
|
|
|
void _onReplaceTap() {
|
|
showCuperModalBottomSheet(
|
|
context: context,
|
|
height: 420.h,
|
|
backgroundColor: AppColors.gray_bg,
|
|
builder:
|
|
(_) => ReplaceDialog(
|
|
currentCollection: widget.currentCollection,
|
|
ticket: widget.ticket,
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onRollTap() {
|
|
safeSetState(() => _isRolled = !_isRolled);
|
|
}
|
|
|
|
void _onEditTap() {}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 8).r,
|
|
child: Slidable(
|
|
enabled: true,
|
|
endActionPane: ActionPane(
|
|
extentRatio: 0.62,
|
|
motion: const StretchMotion(),
|
|
children: [
|
|
const WSpace(8),
|
|
_buildSlidableAction(
|
|
Colors.red.shade50,
|
|
Colors.red,
|
|
CupertinoIcons.trash,
|
|
_onDeleteTap,
|
|
),
|
|
const WSpace(8),
|
|
_buildSlidableAction(
|
|
Colors.blue.shade50,
|
|
Colors.blue,
|
|
CupertinoIcons.repeat,
|
|
_onRollTap,
|
|
),
|
|
const WSpace(8),
|
|
_buildSlidableAction(
|
|
AppColors.secondary,
|
|
AppColors.primary,
|
|
CupertinoIcons.move,
|
|
_onReplaceTap,
|
|
),
|
|
],
|
|
),
|
|
child: Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12).r,
|
|
color: Colors.white,
|
|
),
|
|
constraints: BoxConstraints(minHeight: 50.h),
|
|
child: Stack(
|
|
children: [
|
|
SizedBox(
|
|
height: 50.h,
|
|
width: double.infinity,
|
|
child: DecoratedBox(decoration: getDecoration()),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(12).r,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildImage(),
|
|
Expanded(child: _buildText(context)),
|
|
_buildEditButton(),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildEditButton() {
|
|
return GestureDetector(
|
|
onTap: _onEditTap,
|
|
child: Assets.icons.typeEdit.image(height: 24.h, width: 24.w),
|
|
);
|
|
}
|
|
|
|
Widget _buildSlidableAction(
|
|
Color backgroundColor,
|
|
Color foregroundColor,
|
|
IconData icon,
|
|
VoidCallback onPressed,
|
|
) {
|
|
return SlidableAction(
|
|
borderRadius: BorderRadius.circular(12).r,
|
|
onPressed: (_) => onPressed(),
|
|
backgroundColor: backgroundColor,
|
|
foregroundColor: foregroundColor,
|
|
icon: icon,
|
|
);
|
|
}
|
|
|
|
Widget _buildText(BuildContext context) {
|
|
return ReadMoreText(
|
|
_isRolled ? widget.ticket.answer : widget.ticket.question,
|
|
trimMode: TrimMode.Line,
|
|
trimLines: 3,
|
|
trimCollapsedText: '\nРазвернуть',
|
|
trimExpandedText: '\nСвернуть',
|
|
style: Regular16px().style,
|
|
moreStyle: Regular12px().style.copyWith(color: AppColors.primary_blue),
|
|
lessStyle: Regular12px().style.copyWith(color: AppColors.primary_blue),
|
|
);
|
|
}
|
|
|
|
Widget _buildImage() {
|
|
final imageBytes =
|
|
_isRolled ? widget.ticket.answerImage : widget.ticket.questionImage;
|
|
return Wif(
|
|
condition: imageBytes != null,
|
|
builder:
|
|
(context) => Padding(
|
|
padding: const EdgeInsets.only(right: 8).r,
|
|
child: SizedBox.square(
|
|
dimension: 64.r,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(8).r,
|
|
child: Image.memory(imageBytes!, fit: BoxFit.cover),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Декорирование контейнера
|
|
BoxDecoration getDecoration() {
|
|
return BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12).r,
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
_isRolled ? AppColors.answer : AppColors.question,
|
|
Colors.white,
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: const Alignment(-0.6, 1),
|
|
stops: const [0.25, 0.25],
|
|
),
|
|
);
|
|
}
|
|
}
|