lab-5 50
This commit is contained in:
parent
4cd85a2ae9
commit
6b8d71fc3d
33
lib/presentation/dialogs/error_dialog.dart
Normal file
33
lib/presentation/dialogs/error_dialog.dart
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ErrorDialog extends StatelessWidget {
|
||||||
|
final String? error;
|
||||||
|
const ErrorDialog(this.error, {super.key});
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.all(36),
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: Colors.grey,
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.error, color: Colors.white),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Text(
|
||||||
|
error ?? 'UNKNOWN',
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.white),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
12
lib/presentation/dialogs/show_dialog.dart
Normal file
12
lib/presentation/dialogs/show_dialog.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:leonteva_pmu/presentation/dialogs/error_dialog.dart';
|
||||||
|
|
||||||
|
void showErrorDialog(
|
||||||
|
BuildContext context, {
|
||||||
|
required String? error,
|
||||||
|
}) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ErrorDialog(error),
|
||||||
|
);
|
||||||
|
}
|
@ -80,25 +80,7 @@ class _CardState extends State<_Card> {
|
|||||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Align(
|
|
||||||
alignment: Alignment.bottomLeft,
|
|
||||||
child: Container(
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
color: Colors.orangeAccent,
|
|
||||||
borderRadius: BorderRadius.only(
|
|
||||||
topRight: Radius.circular(20),
|
|
||||||
//
|
|
||||||
)),
|
|
||||||
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
|
|
||||||
child: Text(
|
|
||||||
'скидок нет',
|
|
||||||
style: Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.bodyMedium
|
|
||||||
?.copyWith(color: Colors.black),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -33,38 +33,62 @@ class Body extends StatelessWidget {
|
|||||||
const Body({super.key}); // ключи
|
const Body({super.key}); // ключи
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
State<Body> createState() => _BodyState();
|
||||||
final data = [
|
}
|
||||||
CardData('dish',
|
|
||||||
descriptionText: 'delicious',
|
|
||||||
icon: Icons.abc,
|
|
||||||
imageUrl:
|
|
||||||
'https://n1s2.hsmedia.ru/48/2d/63/482d63d02b668677a73a2ffbd791a71b/728x546_1_aaca034dfa8a8c33247bd8cb2ed26817@1700x1275_0xac120003_9749770561671744766.jpeg'),
|
|
||||||
CardData('dish2',
|
|
||||||
descriptionText: 'yes',
|
|
||||||
icon: Icons.access_alarm_outlined,
|
|
||||||
imageUrl:
|
|
||||||
'https://n1s2.hsmedia.ru/48/2d/63/482d63d02b668677a73a2ffbd791a71b/728x546_1_aaca034dfa8a8c33247bd8cb2ed26817@1700x1275_0xac120003_9749770561671744766.jpeg'),
|
|
||||||
CardData('dish3',
|
|
||||||
descriptionText: 'eeee',
|
|
||||||
icon: Icons.access_alarm_rounded,
|
|
||||||
imageUrl:
|
|
||||||
'https://n1s2.hsmedia.ru/48/2d/63/482d63d02b668677a73a2ffbd791a71b/728x546_1_aaca034dfa8a8c33247bd8cb2ed26817@1700x1275_0xac120003_9749770561671744766.jpeg'),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Center(
|
class _BodyState extends State<Body> {
|
||||||
child: SingleChildScrollView(
|
final searchController = TextEditingController();
|
||||||
child: Column(
|
late Future<List<CardData>?> data;
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: data.map((data) {
|
final repo = PotterRepository();
|
||||||
return _Card.fromData(
|
|
||||||
data,
|
@override
|
||||||
onLike: (String title, bool isLiked) =>
|
void initState() {
|
||||||
_showSnackBar(context, title, isLiked),
|
data = repo.loadData(onError: (e) => showErrorDialog(context, error: e));
|
||||||
onTap: () => _navToDetails(context, data),
|
super.initState();
|
||||||
);
|
}
|
||||||
}).toList(),
|
|
||||||
),
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: CupertinoSearchTextField(
|
||||||
|
controller: searchController,
|
||||||
|
onChanged: (search) {
|
||||||
|
setState(() {
|
||||||
|
data = repo.loadData(q: search);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: FutureBuilder<List<CardData>?>(
|
||||||
|
future: data,
|
||||||
|
builder: (context, snapshot) => SingleChildScrollView(
|
||||||
|
child: snapshot.hasData
|
||||||
|
? Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: snapshot.data?.map((data) {
|
||||||
|
return _Card.fromData(
|
||||||
|
data,
|
||||||
|
onLike: (String title, bool isLiked) =>
|
||||||
|
_showSnackBar(context, title, isLiked),
|
||||||
|
onTap: () => _navToDetails(context, data),
|
||||||
|
);
|
||||||
|
}).toList() ??
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
: const CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user