lab 4 done
This commit is contained in:
parent
3a0493fea6
commit
0b1891b87d
15
lib/domain/models/car.dart
Normal file
15
lib/domain/models/car.dart
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class CarData {
|
||||||
|
final String text;
|
||||||
|
final String descriptionCar;
|
||||||
|
final IconData icon;
|
||||||
|
final String? imageUrl;
|
||||||
|
|
||||||
|
CarData(
|
||||||
|
this.text, {
|
||||||
|
required this.descriptionCar,
|
||||||
|
this.icon = Icons.ac_unit_outlined,
|
||||||
|
this.imageUrl,
|
||||||
|
});
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'presentation/home_page/home_page.dart';
|
import 'presentation/home_page/home_page.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
@ -20,10 +21,3 @@ class MyApp extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
37
lib/presentation/details_page/details_page.dart
Normal file
37
lib/presentation/details_page/details_page.dart
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mylab/domain/models/car.dart';
|
||||||
|
|
||||||
|
class DetailsPage extends StatelessWidget {
|
||||||
|
final CarData data;
|
||||||
|
|
||||||
|
const DetailsPage(this.data, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(),
|
||||||
|
body: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 16.0),
|
||||||
|
child: Image.network(
|
||||||
|
data.imageUrl ?? '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4.0),
|
||||||
|
child: Text(
|
||||||
|
data.text,
|
||||||
|
style: Theme.of(context).textTheme.headlineLarge,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
data.descriptionCar,
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,38 +1,33 @@
|
|||||||
part of 'home_page.dart';
|
part of 'home_page.dart';
|
||||||
|
|
||||||
class _CarData {
|
typedef OnLikeCallback = void Function(String title, bool isLike)?;
|
||||||
final String text;
|
|
||||||
final String descriptionCar;
|
|
||||||
final IconData icon;
|
|
||||||
final String? imageUrl;
|
|
||||||
|
|
||||||
_CarData(
|
|
||||||
this.text, {
|
|
||||||
required this.descriptionCar,
|
|
||||||
this.icon = Icons.ac_unit_outlined,
|
|
||||||
this.imageUrl,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class _Car extends StatefulWidget {
|
class _Car extends StatefulWidget {
|
||||||
final String text;
|
final String text;
|
||||||
final String descriptionCar;
|
final String descriptionCar;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
|
final OnLikeCallback onLike;
|
||||||
|
|
||||||
const _Car(
|
const _Car(
|
||||||
this.text, {
|
this.text, {
|
||||||
this.icon = Icons.ac_unit_outlined,
|
this.icon = Icons.ac_unit_outlined,
|
||||||
required this.descriptionCar,
|
required this.descriptionCar,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
});
|
this.onLike,
|
||||||
|
});
|
||||||
|
|
||||||
factory _Car.fromData(_CarData data) => _Car(
|
factory _Car.fromData(
|
||||||
data.text,
|
CarData data, {
|
||||||
descriptionCar: data.descriptionCar,
|
OnLikeCallback onLike,
|
||||||
icon: data.icon,
|
}) =>
|
||||||
imageUrl: data.imageUrl,
|
_Car(
|
||||||
);
|
data.text,
|
||||||
|
descriptionCar: data.descriptionCar,
|
||||||
|
icon: data.icon,
|
||||||
|
imageUrl: data.imageUrl,
|
||||||
|
onLike: onLike,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_Car> createState() => _CarState();
|
State<_Car> createState() => _CarState();
|
||||||
@ -44,6 +39,7 @@ class _CarState extends State<_Car> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
// geest
|
||||||
margin: const EdgeInsets.all(16),
|
margin: const EdgeInsets.all(16),
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -103,29 +99,27 @@ class _CarState extends State<_Car> {
|
|||||||
),
|
),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() => islike = !islike);
|
||||||
islike = !islike;
|
widget.onLike?.call(widget.text, islike);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
child: AnimatedSwitcher(
|
child: AnimatedSwitcher(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 400),
|
||||||
child: islike
|
child: islike
|
||||||
? const Icon(
|
? const Icon(
|
||||||
Icons.add_circle_outline,
|
Icons.add_circle,
|
||||||
color: Colors.redAccent,
|
color: Colors.redAccent,
|
||||||
key: ValueKey<int>(0),
|
key: ValueKey<int>(0),
|
||||||
)
|
)
|
||||||
: const Icon(
|
: const Icon(
|
||||||
Icons.add_circle,
|
Icons.add_circle_outline,
|
||||||
key: ValueKey<int>(1),
|
key: ValueKey<int>(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:mylab/domain/models/car.dart';
|
||||||
|
import 'package:mylab/presentation/details_page/details_page.dart';
|
||||||
part 'car.dart';
|
part 'car.dart';
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
@ -24,39 +27,40 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WidgetBody extends StatelessWidget {
|
class WidgetBody extends StatelessWidget {
|
||||||
const WidgetBody({super.key});
|
const WidgetBody({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final data = [
|
final data = [
|
||||||
_CarData(
|
CarData(
|
||||||
'Vesta',
|
'Vesta',
|
||||||
descriptionCar: 'год: 2021\nпробег: 12000км\nвладельцев: 2',
|
descriptionCar: 'год: 2021\nпробег: 14000км\nвладельцев: 2',
|
||||||
icon: Icons.access_alarm,
|
icon: Icons.access_alarm,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://yandex-images.clstorage.net/9mo9mr339/ee7538_C/G8eJXZRUhfuSJ9OjdqqaieLubYBOeM1UA1msI7Sd_LOgNGnS4z1IcAaQIvJeBUT1gL1zzfQzXO5c6BvSx-0aw2-jrS1VpRXfdwbz5zILb3mWX4kFSm2YIIK4yef1bn8Q9vZbcVDu-1ZFEUPWS2AAJAQJpXr1Rp2umW-b8GJJ3aE49Qla0NDF2aIH8zAEDLoLMaiecc5o37VUiZ9zkF1NwaQV-9PDnfn2hQNB9asA8XBkabeYInUdvvnMqbHSmM0C-BW4KlAANzhCx7Ii1g6YCONbD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-sn6poQgObboRawofStC9oheC2wfaouF5aKL9Cg7cwz1jSaAoH8Onf0YMPkO2DCA4YapttDtv2fG7_pEnI6PXB6dGqYEcD3iuImQhB2jysZkzhsoO_73ScW6kwR4c3Ms4WEqqER3tgU9QHjVNijMxH3ydf7w_U9DHvvqUGz6u5iStW4-LIAxViAdIIRFTypy9HorkDt6e5m5Vg_I3BfrbKGtRgykF4bV5Ujg2TYUjCC9et1-SDGz6xavBqQooivgisluhlTAjUY0kRDkVb8iWkjW-0hPxovpxQab0OTz_ygpUVrwgFdO4Rlk8OXykLwAlda1PhDdH7_eT2qs-A6PCE4tLsa0SA2-2LEEhA1PJpKwWuMAh4I3aa22c1RYX2e0IanKZFDTgq3lcDj9FsAIUHUaBcZ0nUtDLmsqpOi6p7CC4XKuxKCp9vBRGLzBq9K2IGJ3lP-uLxF9wvM0ABNLJHXt2vzILzoVYTS80YJgvHwlTgXmGOm_mypL6hz8cl_8wjmeerAEfW78XSh8OW9eQsRmg0Sn_qvxRVrboLjbpyAB2dYEMG9SDZXwoNG2TFRklVqdDviBDxcet_bEGHIHNIIxKj4AFBXGfGWI_CW_Pp7YUudcO-I_FYGOmySUW3-8',
|
||||||
),
|
),
|
||||||
_CarData(
|
CarData(
|
||||||
'Granta',
|
'Granta',
|
||||||
descriptionCar: 'Год 2018\nпробег: 157000км\nвладельцев: 3',
|
descriptionCar: 'Год 2018\nпробег: 157000км\nвладельцев: 3',
|
||||||
icon: Icons.access_alarm,
|
icon: Icons.access_alarm,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://avatars.mds.yandex.net/get-verba/1535139/2a00000190baa76e30188cfeae4d9b675edf/cattouchret',
|
'https://avatars.mds.yandex.net/get-verba/1535139/2a00000190baa76e30188cfeae4d9b675edf/cattouchret',
|
||||||
),
|
),
|
||||||
_CarData(
|
CarData(
|
||||||
'Iskra',
|
'Iskra',
|
||||||
descriptionCar: 'год 2024\nпробег: 120км\nвладельцев: 1',
|
descriptionCar: 'год 2024\nпробег: 120км\nвладельцев: 1',
|
||||||
icon: Icons.access_alarm,
|
icon: Icons.access_alarm,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://s.auto.drom.ru/i24294/c/photos/fullsize/lada/iskra/lada_iskra_1205438.jpg',
|
'https://s.auto.drom.ru/i24294/c/photos/fullsize/lada/iskra/lada_iskra_1205438.jpg',
|
||||||
),
|
),
|
||||||
_CarData(
|
CarData(
|
||||||
'Niva',
|
'Niva',
|
||||||
descriptionCar: 'год 2022\nпробег: 67000км\nвладельцев: 2',
|
descriptionCar: 'год 2022\nпробег: 67000км\nвладельцев: 2',
|
||||||
icon: Icons.access_alarm,
|
icon: Icons.access_alarm,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://avatars.mds.yandex.net/i?id=4d0abc12a692355be9dddf44bdb701b1_l-7736363-images-thumbs&n=13',
|
'https://avatars.mds.yandex.net/i?id=4d0abc12a692355be9dddf44bdb701b1_l-7736363-images-thumbs&n=13',
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -64,9 +68,37 @@ class WidgetBody extends StatelessWidget {
|
|||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: data.map((e) => _Car.fromData(e)).toList(),
|
children: data
|
||||||
|
.map((data) => GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (context) => DetailsPage(data)),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: _Car.fromData(
|
||||||
|
data,
|
||||||
|
onLike: (String title, bool isLiked) =>
|
||||||
|
_showSnackBar(context, title, isLiked),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void _showSnackBar(BuildContext context, String title, bool isLike) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Lada $title ${isLike ? 'Respect! 🤙' : 'disRespect 👎'}',
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.greenAccent,
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user