This commit is contained in:
Stepan 2024-10-18 17:07:54 +04:00
parent d20378d17b
commit 4aa03f5187

View File

@ -13,6 +13,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Flutter Demo', title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange), colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
useMaterial3: true, useMaterial3: true,
@ -32,15 +33,7 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; final Color _color = Colors.orangeAccent;
Color _color = Colors.orangeAccent;
void _incrementCounter() {
setState(() {
_counter++;
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -49,30 +42,121 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: _color, backgroundColor: _color,
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center( body: const MyWidget(),
child: Column( );
mainAxisAlignment: MainAxisAlignment.center, }
children: <Widget>[ }
const Text(
'You have pushed the button this many times:', class MyWidget extends StatelessWidget {
), const MyWidget({super.key});
Text(
'$_counter', @override
style: Theme.of(context).textTheme.headlineMedium, Widget build(BuildContext context) {
), final data = [
if (_counter > 10) _CartData(
Text( 'FarCry 1',
'Wtf bro?', descriptionText: 'Читать описание',
style: Theme.of(context).textTheme.headlineMedium, imageUrl:
'https://avatars.mds.yandex.net/i?id=e8dbfc281bbeac76d49d5f83b9b872d9_l-5246113-images-thumbs&n=13',
),
_CartData(
'FarCry 2',
descriptionText: 'Читать описание',
imageUrl:
'https://avatars.mds.yandex.net/get-entity_search/2102351/931749212/S600xU_2x'),
_CartData(
'FarCry 3',
descriptionText: 'Читать описание',
imageUrl: 'https://i.pinimg.com/736x/ab/32/cc/ab32cc12f75b5c304ec88af78c5c0dc3.jpg'
)
];
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
),
);
}
}
class _CartData {
final String text;
final String descriptionText;
final String? imageUrl;
_CartData(
this.text, {
required this.descriptionText,
this.imageUrl,
});
}
class _Card extends StatelessWidget {
final String text;
final String descriptionText;
final String? imageUrl;
const _Card(
this.text, {
required this.descriptionText,
this.imageUrl,
});
factory _Card.fromData(_CartData data) => _Card(
data.text,
descriptionText: data.descriptionText,
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: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 150,
width: 150,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
), ),
),
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,
)
],
),
),
),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( );
onPressed: _incrementCounter,
backgroundColor: _color,
tooltip: 'Increment',
child: const Icon(Icons.add),
), );
} }
} }