first commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../data/catalog/bundled_sign_catalog.dart';
|
||||
import '../../domain/sign_catalog.dart';
|
||||
import '../../domain/traffic_sign.dart';
|
||||
import '../../theme/tokens.dart';
|
||||
import '../../ui/ui.dart';
|
||||
import '../theme/sign_style.dart';
|
||||
import 'sign_detail_page.dart';
|
||||
import 'sign_glyph.dart';
|
||||
|
||||
class CatalogPage extends StatefulWidget {
|
||||
const CatalogPage({super.key, this.catalog});
|
||||
|
||||
final SignCatalog? catalog;
|
||||
|
||||
@override
|
||||
State<CatalogPage> createState() => _CatalogPageState();
|
||||
}
|
||||
|
||||
class _CatalogPageState extends State<CatalogPage> {
|
||||
final _query = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_query.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final catalog = widget.catalog ?? bundledSignCatalog;
|
||||
final query = _query.text.trim().toLowerCase();
|
||||
final signs = catalog.signs.where((sign) {
|
||||
if (query.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
return sign.code.toLowerCase().contains(query) ||
|
||||
sign.name.toLowerCase().contains(query);
|
||||
}).toList();
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
backgroundColor: AppColors.of(context, AppColors.groupedBackground),
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Справочник')),
|
||||
child: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.s6),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.gutter,
|
||||
AppSpacing.s3,
|
||||
AppSpacing.gutter,
|
||||
AppSpacing.s2,
|
||||
),
|
||||
child: AppTextField(
|
||||
controller: _query,
|
||||
onChanged: (_) => setState(() {}),
|
||||
placeholder: 'Номер или название, например 3.27',
|
||||
prefixIcon: CupertinoIcons.search,
|
||||
),
|
||||
),
|
||||
if (signs.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(AppSpacing.s5),
|
||||
child: AppText.footnote(
|
||||
'Ничего не найдено',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
)
|
||||
else
|
||||
for (final category in SignCategory.values)
|
||||
_CategorySection(
|
||||
category: category,
|
||||
signs: signs
|
||||
.where((sign) => sign.category == category)
|
||||
.toList(),
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
AppSpacing.gutter,
|
||||
AppSpacing.s4,
|
||||
AppSpacing.gutter,
|
||||
0,
|
||||
),
|
||||
child: AppText.footnote(signImageAttribution),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategorySection extends StatelessWidget {
|
||||
const _CategorySection({required this.category, required this.signs});
|
||||
|
||||
final SignCategory category;
|
||||
final List<TrafficSign> signs;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (signs.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return AppListSection(
|
||||
header: categoryTitle(category),
|
||||
separatorIndent: 76,
|
||||
children: [
|
||||
for (final sign in signs)
|
||||
AppListTile(
|
||||
leading: SignGlyph(sign: sign, size: 44),
|
||||
title: sign.name,
|
||||
subtitle: sign.action,
|
||||
value: sign.code,
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute<void>(
|
||||
builder: (_) => SignDetailPage(sign: sign),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user