2024-09-13 23:03:23 +04:00
|
|
|
import 'package:flutter/material.dart';
|
2024-10-08 23:25:53 +04:00
|
|
|
import 'card_repository.dart';
|
|
|
|
import 'card_item.dart';
|
|
|
|
import 'card_model.dart'; // Убедитесь, что этот импорт присутствует
|
2024-09-13 23:03:23 +04:00
|
|
|
|
|
|
|
void main() {
|
2024-09-25 00:25:31 +04:00
|
|
|
runApp(MyApp());
|
2024-09-13 23:03:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2024-10-08 23:25:53 +04:00
|
|
|
title: 'Card App',
|
2024-09-13 23:03:23 +04:00
|
|
|
theme: ThemeData(
|
2024-09-25 00:25:31 +04:00
|
|
|
primarySwatch: Colors.blue,
|
2024-09-13 23:03:23 +04:00
|
|
|
),
|
2024-09-25 00:25:31 +04:00
|
|
|
home: CardListScreen(),
|
2024-09-13 23:03:23 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-08 23:25:53 +04:00
|
|
|
class CardListScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_CardListScreenState createState() => _CardListScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CardListScreenState extends State<CardListScreen> {
|
|
|
|
List<CardModel> cards = [];
|
|
|
|
List<CardModel> filteredCards = [];
|
|
|
|
bool isLoading = true;
|
|
|
|
String searchQuery = '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
fetchCards();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> fetchCards() async {
|
|
|
|
final repository = CardRepository();
|
|
|
|
try {
|
|
|
|
final fetchedCards = await repository.fetchCards();
|
|
|
|
setState(() {
|
|
|
|
cards = fetchedCards;
|
|
|
|
filteredCards = cards;
|
|
|
|
isLoading = false;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
setState(() {
|
|
|
|
isLoading = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void filterCards(String query) {
|
|
|
|
setState(() {
|
|
|
|
searchQuery = query;
|
|
|
|
filteredCards = cards.where((card) {
|
|
|
|
return card.value.toLowerCase().contains(query.toLowerCase()) ||
|
|
|
|
card.suit.toLowerCase().contains(query.toLowerCase());
|
|
|
|
}).toList();
|
|
|
|
});
|
|
|
|
}
|
2024-09-13 23:03:23 +04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2024-10-08 23:25:53 +04:00
|
|
|
title: Text('Колода карт'),
|
|
|
|
bottom: PreferredSize(
|
|
|
|
preferredSize: Size.fromHeight(50.0),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'Поиск по значению или масти',
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
|
|
|
onChanged: filterCards,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-09-13 23:03:23 +04:00
|
|
|
),
|
2024-10-08 23:25:53 +04:00
|
|
|
body: isLoading
|
|
|
|
? Center(child: CircularProgressIndicator())
|
|
|
|
: GridView.builder(
|
2024-09-25 00:25:31 +04:00
|
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
2024-10-08 23:25:53 +04:00
|
|
|
crossAxisCount: 2,
|
|
|
|
childAspectRatio: 1.9,
|
2024-09-25 00:25:31 +04:00
|
|
|
),
|
2024-10-08 23:25:53 +04:00
|
|
|
itemCount: filteredCards.length,
|
2024-09-25 00:25:31 +04:00
|
|
|
itemBuilder: (context, index) {
|
2024-10-08 23:25:53 +04:00
|
|
|
final card = filteredCards[index];
|
|
|
|
return CardItem(
|
|
|
|
suit: card.suit,
|
|
|
|
value: card.value,
|
|
|
|
imageUrl: card.imageUrl,
|
2024-09-25 00:25:31 +04:00
|
|
|
);
|
|
|
|
},
|
2024-09-13 23:03:23 +04:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|