Lab1-2-3
This commit is contained in:
parent
7b6f46c84b
commit
811224b5d4
55
lib/Lr2/Car.dart
Normal file
55
lib/Lr2/Car.dart
Normal file
@ -0,0 +1,55 @@
|
||||
import 'dart:math';
|
||||
|
||||
enum Car{Lada, BMW, Skoda}
|
||||
|
||||
extension CarX on Car{
|
||||
static List<Car> generateRandomCar(int n){
|
||||
var rnd = Random();
|
||||
return List.generate(n, (i) => Car.values[rnd.nextInt(Car.values.length)]);
|
||||
}
|
||||
}
|
||||
|
||||
class NewCar{
|
||||
final String name;
|
||||
double cost;
|
||||
|
||||
NewCar(this.name, this.cost);
|
||||
|
||||
String get info => 'New car: $name, cost: $cost';
|
||||
}
|
||||
|
||||
class OldCar extends NewCar{
|
||||
final int mileage;
|
||||
|
||||
OldCar(
|
||||
super.name,
|
||||
super.cost, {
|
||||
required this.mileage
|
||||
});
|
||||
|
||||
double costOldCar(cost, mileage){
|
||||
return cost - (mileage * 0.7);
|
||||
}
|
||||
//String info() => 'Old car: $name, cost: $cost, mileage: $mileage';
|
||||
}
|
||||
|
||||
void main(){
|
||||
asynchronous();
|
||||
}
|
||||
|
||||
Future<void> asynchronous() async{
|
||||
for (int i = 1; i < 5; i++) {
|
||||
List<Car> car = CarX.generateRandomCar(1);
|
||||
final auto = NewCar('$car', i * 1000000);
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 10),
|
||||
() => print(auto.info),
|
||||
);
|
||||
final oldAuto = OldCar('$car', i * 1000000 - (i * 100000 * 0.7), mileage: i * 100000);
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 20),
|
||||
() => print(oldAuto.info),
|
||||
);
|
||||
print('');
|
||||
}
|
||||
}
|
163
lib/main.dart
163
lib/main.dart
@ -15,7 +15,7 @@ class MyApp extends StatelessWidget {
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Юнусов Нияз Наилевич'),
|
||||
home: const MyHomePage(title: 'Тренажёры'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -28,12 +28,7 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
final Color _color = Colors.orangeAccent;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -42,24 +37,144 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: const MyWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CardData {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
_CardData(
|
||||
this.text, {
|
||||
required this.descriptionText,
|
||||
this.icon = Icons.accessibility_new,
|
||||
this.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
class MyWidget extends StatelessWidget {
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = [
|
||||
_CardData(
|
||||
'Силовой',
|
||||
descriptionText: 'Задействуются все группы мышц',
|
||||
imageUrl:
|
||||
'https://sportavsem.ru/image/cache/catalog/multistancii-i-silovye-kompleksy/2/data-public-shop-products-29-20-2029-images-11573-11573-970-1000x1000.gif',
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
_CardData(
|
||||
'Гребной',
|
||||
descriptionText: 'Повышает выносливость',
|
||||
icon: Icons.directions_bike,
|
||||
imageUrl: 'https://avatars.mds.yandex.net/get-mpic/5303146/img_id2968731285466973579.jpeg/orig'
|
||||
),
|
||||
_CardData(
|
||||
'Для пресса',
|
||||
descriptionText: 'Качает пресс',
|
||||
icon: Icons.local_atm,
|
||||
imageUrl: 'https://avatars.mds.yandex.net/i?id=ea33ce886c474cb617b94e45ec9cffde350c2a75-6254930-images-thumbs&n=13'
|
||||
),
|
||||
];
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: data.map((e) => _Card.fromData(e)).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Card extends StatelessWidget {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
const _Card(this.text, {
|
||||
this.icon = Icons.ac_unit_outlined,
|
||||
required this.descriptionText,
|
||||
this.imageUrl,
|
||||
});
|
||||
|
||||
factory _Card.fromData(_CardData data) =>
|
||||
_Card(
|
||||
data.text,
|
||||
descriptionText: data.descriptionText,
|
||||
icon: data.icon,
|
||||
imageUrl: data.imageUrl,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: Colors.grey, width: 2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(.5),
|
||||
spreadRadius: 4,
|
||||
offset: const Offset(0, 5),
|
||||
blurRadius: 8,
|
||||
)
|
||||
]
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: SizedBox(
|
||||
height: 140,
|
||||
width: 100,
|
||||
child: Image.network(
|
||||
imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text,
|
||||
style: Theme
|
||||
.of(context)
|
||||
.textTheme
|
||||
.headlineLarge,
|
||||
),
|
||||
Text(
|
||||
descriptionText,
|
||||
style: Theme
|
||||
.of(context)
|
||||
.textTheme
|
||||
.bodyLarge,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Icon(icon),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user