112 lines
3.5 KiB
Dart
112 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../providers/instruction_provider.dart';
|
|
import 'add_edit_instruction_page.dart';
|
|
import 'instruction_detail_page.dart';
|
|
|
|
class InstructionListPage extends StatefulWidget {
|
|
const InstructionListPage({super.key});
|
|
|
|
@override
|
|
State<InstructionListPage> createState() => _InstructionListPageState();
|
|
}
|
|
|
|
class _InstructionListPageState extends State<InstructionListPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Future.microtask(() =>
|
|
Provider.of<InstructionProvider>(context, listen: false)
|
|
.loadInstructions());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Список инструктажей'),
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
),
|
|
body: Consumer<InstructionProvider>(
|
|
builder: (context, provider, child) {
|
|
return Column(
|
|
children: [
|
|
_buildFilterChips(provider),
|
|
if (provider.isLoading)
|
|
const Expanded(child: Center(child: CircularProgressIndicator()))
|
|
else
|
|
_buildInstructionList(provider),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (context) => const AddEditInstructionPage()),
|
|
);
|
|
},
|
|
tooltip: 'Добавить инструктаж',
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFilterChips(InstructionProvider provider) {
|
|
if (provider.allAvailableTags.isEmpty) return const SizedBox.shrink();
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Wrap(
|
|
spacing: 8.0,
|
|
runSpacing: 4.0,
|
|
children: provider.allAvailableTags.map((tag) {
|
|
final isSelected = provider.selectedTags.contains(tag);
|
|
return FilterChip(
|
|
label: Text(tag),
|
|
selected: isSelected,
|
|
onSelected: (_) => provider.toggleTagFilter(tag),
|
|
selectedColor: Theme.of(context).colorScheme.primaryContainer,
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInstructionList(InstructionProvider provider) {
|
|
if (provider.filteredInstructions.isEmpty && !provider.isLoading) {
|
|
return const Expanded(
|
|
child: Center(
|
|
child: Text(
|
|
'Инструктажи не найдены.\nПопробуйте сбросить фильтры или добавить новый.',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
return Expanded(
|
|
child: ListView.builder(
|
|
itemCount: provider.filteredInstructions.length,
|
|
itemBuilder: (context, index) {
|
|
final instruction = provider.filteredInstructions[index];
|
|
return Card(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: ListTile(
|
|
title: Text(instruction.title),
|
|
subtitle: Text(
|
|
'Теги: ${instruction.tags.join(', ')}',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
onTap: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (ctx) => InstructionDetailPage(instruction: instruction),
|
|
));
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |