lab 5 final done
This commit is contained in:
parent
0ca1277fb3
commit
65f3b68ff5
@ -19,11 +19,15 @@ class CarRepository extends ApiInterface {
|
||||
Future<List<CarData>?> loadData({String? q, OnErrorCallback? onError, int limit = 20}) async {
|
||||
try {
|
||||
const String url = '$_baseUrl/GetModelsForMakeYear/make/honda/modelyear/1990?format=json';
|
||||
const String searchurl = '$_baseUrl/GetModelsForMakeYear/make/[name_count]/modelyear/1990?format=json';
|
||||
|
||||
final String finalUrl = q != null ? searchurl.replaceFirst('[name_count]', q) : url;
|
||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(finalUrl);
|
||||
|
||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(url);
|
||||
print('Response data: ${response.data}');
|
||||
final CarDto dto = CarDto.fromJson(response.data as Map<String, dynamic>);
|
||||
final List<CarData>? data = dto.results?.map((e) => e.toDomain()).toList();
|
||||
|
||||
// Ограничиваем количество возвращаемых записей до 'limit'
|
||||
if (data != null && data.length > limit) {
|
||||
return data.sublist(0, limit);
|
||||
|
@ -52,9 +52,9 @@ class _CarState extends State<_Car> {
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(.5),
|
||||
color: Colors.deepPurple.withOpacity(.4),
|
||||
spreadRadius: 4,
|
||||
offset: const Offset(0, 5),
|
||||
offset: const Offset(0, 0),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
@ -83,11 +83,11 @@ class _CarState extends State<_Car> {
|
||||
children: [
|
||||
Text(
|
||||
widget.text,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
widget.descriptionCar,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.normal),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@ -49,16 +49,17 @@ class _BodyState extends State<Body> {
|
||||
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);
|
||||
// // }
|
||||
// ),
|
||||
// ),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: CupertinoSearchTextField(
|
||||
controller: searchController,
|
||||
onChanged: (search) {
|
||||
setState(() {
|
||||
data = repo.loadData(q: search);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: FutureBuilder<List<CarData>?>(
|
||||
@ -98,10 +99,10 @@ class _BodyState extends State<Body> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
'Lada $title ${isLiked ? 'Respect! 🤙' : 'disRespect 👎'}',
|
||||
'Car $title ${isLiked ? 'Respect! 🤙' : 'disRespect 👎'}',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
backgroundColor: Colors.orangeAccent,
|
||||
backgroundColor: Colors.deepPurple,
|
||||
duration: const Duration(seconds: 1),
|
||||
));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user