This commit is contained in:
antoc0der 2024-09-17 22:32:44 +04:00
parent c3c60ba6f1
commit 2532f84f4b

View File

@ -7,12 +7,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: 'Nasyrov Arthur PIbd-33'), home: const MyHomePage(title: 'Nasyrov Arthur PIbd-33'),
@ -23,8 +23,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
@ -32,39 +30,131 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; final Color _color = Colors.deepPurple;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary, 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});
@override
Widget build(BuildContext context) {
final data = [
_CardData(text: 'text', descText: 'descText', imageUrl: 'https://sun9-7.userapi.com/impg/5Lbmz05PKIjm3vWMa91N-nD2Zrx1IYHxhLSiKg/N9rlBPsRwPM.jpg?size=872x703&quality=96&sign=8e317544d6f5b07c225172ab73f80a81&type=album'),
_CardData(
text: 'text1', descText: 'descText1', icon: Icons.account_balance, imageUrl: 'https://sun9-29.userapi.com/impg/qonYc1ab9zsuUPghZ8fkk0JNfo5aDPO-kV6yOw/pYmeYWPQ9Mw.jpg?size=749x776&quality=96&sign=6363bea3e48e498a84011827b157cdf3&type=album'),
_CardData(
text: 'text2',
descText: 'descText2',
icon: Icons.add_call,
imageUrl: 'https://cdn.culture.ru/images/63e764eb-458c-53f6-b161-79521a602d0c',)
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _HelloWidget.fromData(e)).toList(),
),
),
);
}
}
class _HelloWidget extends StatelessWidget {
final String text;
final IconData icon;
final String descText;
final String? imageUrl;
const _HelloWidget(this.text,
{this.icon = Icons.ac_unit_sharp, required this.descText, this.imageUrl});
factory _HelloWidget.fromData(_CardData data) => _HelloWidget(
data.text,
descText: data.descText,
icon: data.icon,
imageUrl: data.imageUrl,
);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Container(
margin: const EdgeInsets.only(top: 10),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.pinkAccent,
width: 3,
)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: SizedBox(
height: 140,
width: 100,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
), ),
Text( Flexible(
'$_counter', child: Padding(
style: Theme.of(context).textTheme.headlineMedium, padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
selectionColor: Colors.white,
text,
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
descText,
style: Theme.of(context).textTheme.headlineSmall,
)
],
),
),
), ),
const Spacer(),
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(icon),
)
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( );
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), );
} }
} }
class _CardData {
final String text;
final IconData icon;
final String descText;
final String? imageUrl;
_CardData({
required this.text,
this.icon = Icons.accessibility_new,
required this.descText,
this.imageUrl,
});
}