lab 3 complete
This commit is contained in:
parent
d737dbd252
commit
0cb17c812b
151
lib/main.dart
151
lib/main.dart
@ -1,5 +1,3 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
@ -9,11 +7,13 @@ void main() {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange),
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Яковлев Максим Григорьевич'),
|
||||
@ -24,8 +24,6 @@ class MyApp extends StatelessWidget {
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
@ -33,15 +31,7 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
Color _color = Colors.orange;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter += 10;
|
||||
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||
});
|
||||
}
|
||||
final Color _color = Colors.orangeAccent;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -50,29 +40,122 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
backgroundColor: _color,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
body: const MyWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyWidget extends StatelessWidget {
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = [
|
||||
_CartData(
|
||||
'Warhammer 40000:Space Marine 2',
|
||||
descriptionText: 'Читать новость',
|
||||
imageUrl:
|
||||
'https://news.xbox.com/en-us/wp-content/uploads/sites/2/2021/12/SpaceMarine2_TemporaryArtwork_4K_logo.jpg',
|
||||
),
|
||||
_CartData('Risk of rain 2',
|
||||
descriptionText: 'Читать новость',
|
||||
imageUrl:
|
||||
'https://digiseller.mycdn.ink/preview/990130/p1_3675944_49000546.jpg'),
|
||||
_CartData(
|
||||
'Linage 2',
|
||||
descriptionText: 'Читать новость',
|
||||
imageUrl: 'https://avatars.mds.yandex.net/i?id=67f86892afc08862da2521e5b4cf4439_l-9569150-images-thumbs&n=13'
|
||||
)
|
||||
];
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: data.map((e) => _Card.fromData(e)).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CartData {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
|
||||
//final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
_CartData(
|
||||
this.text, {
|
||||
required this.descriptionText,
|
||||
//required this.icon,
|
||||
this.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
class _Card extends StatelessWidget {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
|
||||
//final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
const _Card(
|
||||
this.text, {
|
||||
//required this.icon,
|
||||
required this.descriptionText,
|
||||
this.imageUrl,
|
||||
});
|
||||
|
||||
factory _Card.fromData(_CartData data) => _Card(
|
||||
data.text,
|
||||
descriptionText: data.descriptionText,
|
||||
//icon: data.icon,
|
||||
imageUrl: data.imageUrl,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(top: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orangeAccent,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: Colors.grey, width: 2)),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 140,
|
||||
width: 150,
|
||||
child: Image.network(
|
||||
imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Text(
|
||||
descriptionText,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_counter > 200)
|
||||
Text(
|
||||
'Stop clicking!',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
backgroundColor: _color,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), );
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user