lab 3 + p.s. устал

This commit is contained in:
Леонид Малафеев 2024-10-14 16:35:53 +04:00
parent 5e4d0b72f9
commit 074eba0fe6

View File

@ -29,22 +29,6 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
final List<FortniteSkin> skins = [
FortniteSkin(
imageUrl: 'assets/images/shark.png',
name: 'Safety First Steve',
description: 'Dont make him blow the whistle.!',
rarity: Rarity.epic,
),
FortniteSkin(
imageUrl: 'assets/images/raven.png',
name: 'Raven',
description: 'Brooding master of dark skies.',
rarity: Rarity.legendary,
),
];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -52,37 +36,109 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title), title: Text(widget.title),
), ),
body: ListView.builder( body: const MyWidget(),
itemCount: skins.length, );
itemBuilder: (context, index) { }
final skin = skins[index]; }
return Padding( final List<FortniteSkin> skins = [
padding: const EdgeInsets.all(8.0), FortniteSkin(
child: Column( imageUrl: 'assets/images/shark.png',
crossAxisAlignment: CrossAxisAlignment.start, name: 'Safety First Steve',
children: [ description: 'Dont make him blow the whistle.!',
Image.asset( rarity: Rarity.epic,
skin.imageUrl, ),
height: 150, FortniteSkin(
width: 150, imageUrl: 'assets/images/raven.png',
), name: 'Raven',
Text( description: 'Brooding master of dark skies.',
skin.name, rarity: Rarity.legendary,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ),
), ];
Text(skin.description), class MyWidget extends StatelessWidget{
Text('Редкость: ${getRarityString(skin.rarity)}'), const MyWidget({super.key});
const SizedBox(height: 20),
], @override
), Widget build(BuildContext context) {
); return Center(
}, child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (var skin in skins)
_Card(
name: skin.name,
description: skin.description,
imageUrl: skin.imageUrl,
),
],
),
), ),
); );
} }
} }
class _Card extends StatelessWidget {
final String name;
final String imageUrl;
final String description;
const _Card({
required this.name,
required this.description,
required this.imageUrl,
});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.greenAccent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black,
width: 3,
)
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(15),
child: SizedBox(
height: 150,
width: 120,
child: Image.asset(
imageUrl,
fit: BoxFit.cover,
errorBuilder: (_,__,___) => const Placeholder(),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
Text(
description,
style: const TextStyle(fontSize: 15),
)
],
),
),
),
],
),
);
}
}
class FortniteSkin { class FortniteSkin {
final String imageUrl; final String imageUrl;