83 lines
2.9 KiB
Dart
83 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '/models/instruction.dart';
|
|
import '/providers/instruction_provider.dart';
|
|
import 'add_edit_instruction_page.dart';
|
|
|
|
class InstructionDetailPage extends StatelessWidget {
|
|
final Instruction instruction;
|
|
|
|
const InstructionDetailPage({super.key, required this.instruction});
|
|
|
|
void _deleteInstruction(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('Подтверждение'),
|
|
content: const Text('Вы уверены, что хотите удалить этот инструктаж?'),
|
|
actions: [
|
|
TextButton(onPressed: () => Navigator.of(ctx).pop(), child: const Text('Отмена')),
|
|
TextButton(
|
|
onPressed: () {
|
|
context.read<InstructionProvider>().deleteInstruction(instruction.id!);
|
|
Navigator.of(ctx).pop();
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: const Text('Удалить', style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(instruction.title, overflow: TextOverflow.ellipsis),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.edit),
|
|
tooltip: 'Редактировать',
|
|
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (ctx) => AddEditInstructionPage(initialInstruction: instruction),
|
|
)),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete),
|
|
tooltip: 'Удалить',
|
|
onPressed: () => _deleteInstruction(context),
|
|
),
|
|
],
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: ListView(
|
|
children: [
|
|
Text('Теги:', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
if (instruction.tags.isEmpty)
|
|
const Text('Теги отсутствуют')
|
|
else
|
|
Wrap(
|
|
spacing: 8.0,
|
|
runSpacing: 4.0,
|
|
children: instruction.tags.map((tag) => Chip(label: Text(tag))).toList(),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Text('Содержание:', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withOpacity(0.05),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Text(instruction.content, style: const TextStyle(fontSize: 16, height: 1.5)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |