Compare commits

...

1 Commits
master ... lab3

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

View File

@ -9,12 +9,12 @@ void main() {
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Flutter Demo', title: 'Flutter Demo',
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true, useMaterial3: true,
), ),
home: const MyHomePage(title: 'KozyrevSS'), home: const MyHomePage(title: 'KozyrevSS'),
@ -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; @override
Color _color = Colors.white; Widget build(BuildContext context) {
void _incrementCounter() { final data = [
setState(() { const _CardData(
_counter++; "First",
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); 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(
appBar: AppBar(
backgroundColor: Colors.purple,
title: Text(widget.title),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
),
)));
} }
}
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Container(
appBar: AppBar( margin: const EdgeInsets.all(15),
backgroundColor: _color, padding: const EdgeInsets.all(15),
title: Text(widget.title), decoration: BoxDecoration(
), color: Colors.purple,
body: Center( borderRadius: BorderRadius.circular(20),
child: Column( border: Border.all(color: Colors.green, width: 2),
mainAxisAlignment: MainAxisAlignment.center, boxShadow: [
children: <Widget>[ BoxShadow(
const Text( color: Colors.grey.withOpacity(.4),
'You have pushed the button this many times:', offset: const Offset(0, 5),
blurRadius: 6,
spreadRadius: 3
), ),
Text( ]
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
if (_counter > 10)
const Text("Why are you doing this?",)
],
),
), ),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter, child: Row(
tooltip: 'Increment', mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: const Icon(Icons.add), 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(
description,
style: Theme.of(context).textTheme.bodySmall,
)
],
),
),
Padding(
padding: const EdgeInsets.only(left: 8),
child: Icon(icon),
)
],
),
);
} }
} }