Compare commits

...

1 Commits
master ... lab3

Author SHA1 Message Date
Serxiolog
e802b33fb2 Third Laba 2024-10-02 17:54:28 +04:00

View File

@ -25,8 +25,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title}); const MyHomePage({super.key, required this.title});
final String title; final String title;
@override @override
@ -34,42 +32,132 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Color _color = Colors.white;
void _incrementCounter() {
setState(() {
_counter++;
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final data = [
const _CardData(
"First",
description: "SomeText",
),
const _CardData(
"Second",
icon: Icons.gamepad,
description: "ManyText",
imageUrl: "https://i.pinimg.com/originals/21/73/24/217324138d1bbc91663d4943ebe5de60.jpg",
),
const _CardData(
"Third",
icon: Icons.offline_bolt_outlined,
description: "Wow >_<",
),
];
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: _color, backgroundColor: Colors.purple,
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center( body: Center(
child: SingleChildScrollView(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: data.map((e) => _Card.fromData(e)).toList(),
const Text( ),
'You have pushed the button this many times:', )));
}
}
class _CardData {
final String text;
final String description;
final IconData icon;
final String imageUrl;
const _CardData(
this.text, {
required this.description,
this.icon = Icons.add_call,
this.imageUrl =
"https://i.pinimg.com/736x/5f/14/b3/5f14b3f14fcd157bc4dffa39085396cc.jpg",
});
}
class _Card extends StatelessWidget {
final String text;
final String description;
final IconData icon;
final String imageUrl;
const _Card(
this.text, {
required this.description,
this.icon = Icons.add_call,
required this.imageUrl,
});
factory _Card.fromData(_CardData data) => _Card(
data.text,
description: data.description,
icon: data.icon,
imageUrl: data.imageUrl,
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(15),
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: Colors.purple,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.green, width: 2),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.4),
offset: const Offset(0, 5),
blurRadius: 6,
spreadRadius: 3
),
]
),
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(),
),
),
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text * 10,
style: Theme.of(context).textTheme.headlineLarge,
), ),
Text( Text(
'$_counter', description,
style: Theme.of(context).textTheme.headlineMedium, style: Theme.of(context).textTheme.bodySmall,
), )
if (_counter > 10)
const Text("Why are you doing this?",)
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( Padding(
onPressed: _incrementCounter, padding: const EdgeInsets.only(left: 8),
tooltip: 'Increment', child: Icon(icon),
child: const Icon(Icons.add), )
), ); ],
),
);
} }
} }