This commit is contained in:
revengel66
2024-10-03 16:14:37 +04:00
parent b0cc403d56
commit 7cc51a403e

View File

@@ -1,8 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
@@ -25,56 +22,147 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Color _color = Colors.orangeAccent;
void _incrementCounter() {
setState(() {
_counter++;
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
});
}
final Color _color = Colors.orangeAccent;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: _color,
title: Text('Катышева Наталья Евгеньевна'),
title: Text(widget.title),
),
body: Center(
child: Column(
body: const MyWidget(),
);
}
}
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
if (_counter > 10)
Text(
'Why are you clicking?',
style: Theme.of(context).textTheme.headlineMedium,
),
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
],
@override
Widget build(BuildContext context) {
final data = [
_CardDate(
'Какая-то новость',
description: 'В данном блоке рекомендуем разместить краткую информацию',
imgUrl:
'https://universal.revengel.ru/assets/cache_image/images/services/3_731x487_1cb.png',
),
_CardDate(
'Ещё какая-то новость',
description: 'В данном блоке рекомендуем разместить краткую информацию',
imgUrl:
"https://universal.revengel.ru/assets/cache_image/images/services/2_731x487_1cb.png",
),
_CardDate(
'Ещё одна новость',
description: 'В данном блоке рекомендуем разместить краткую информацию',
imgUrl:
"https://universal.revengel.ru/assets/cache_image/images/services/1_731x487_1cb.png",
)
];
return Center(
child: SingleChildScrollView(
padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
child: Column(
children: data.map((e) => _Card.fromData(e)).toList(),
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: _color,
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class _CardDate {
final String text;
final String description;
final String? imgUrl;
_CardDate(
this.text, {
required this.description,
this.imgUrl,
});
}
class _Card extends StatelessWidget {
final String text;
final String description;
final String? imgUrl;
const _Card(
this.text, {
required this.description,
this.imgUrl,
});
factory _Card.fromData(_CardDate data) => _Card(
data.text,
description: data.description,
imgUrl: data.imgUrl,
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(bottom: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 1,
offset: const Offset(0, 0),
blurRadius: 15,
)
]),
child: Column(children: [
ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20), topRight: Radius.circular(20)),
child: Image.network(
imgUrl ?? '',
errorBuilder: (_, __, ___) => const Placeholder(),
fit: BoxFit.fitWidth,
),
),
Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom:10),
child: Text(
text,
style: const TextStyle(
color: Color(0xff4c4c4c),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
),
Text(
description,
style: const TextStyle(
color: Color(0xff9c9c9c),
fontSize: 20,
fontWeight: FontWeight.normal,
),
),
],
),
),
]),
);
}
}