PIbd31_Razubaev.S.M._PMU/lib/main.dart

181 lines
6.1 KiB
Dart
Raw Normal View History

2024-09-19 19:10:50 +04:00
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Разубаев Сергей Михайлович'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
2024-10-03 20:02:24 +04:00
body: const MyWidget(),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(
'Зов Ктулху',
descriptionText: 'Лучше бы не находить разгадку, объединяющую сошедших с ума творцов...',
imageUrl: 'https://lovecraft.country/images/bibliography/call-of-cthulhu-mini.webp'
),
_CardData(
'Хребты безумия',
descriptionText: '«Хребты безумия» написаны в документальной манере повествования, постепенно привыкая к которой, становишься свидетелем особой реальности описываемых событий.',
icon: Icons.hail,
imageUrl: 'https://lovecraft.country/images/bibliography/At-the-Mountains-of-Madness-mini.webp'
),
_CardData('Тень над Инсмутом', descriptionText: 'Инсмут, маленький рыбацкий городок неподалеку от Аркхэма, уже много лет имеет дурную славу. В округе ходят жуткие истории о его угрюмых и уродливых жителях, от которых лучше держаться подальше.', icon: Icons.warning_amber, imageUrl: 'https://lovecraft.country/images/bibliography/The-Shadow-over-Innsmouth.webp')
];
return Center(
child: SingleChildScrollView(
2024-09-19 19:10:50 +04:00
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
2024-10-03 20:02:24 +04:00
children: data.map((e) => _Card.fromData(e)).toList(),
),
),
);
}
}
class _CardData {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
_CardData(this.text,
{required this.descriptionText,
this.icon = Icons.ac_unit_outlined,
this.imageUrl});
}
class _Card extends StatelessWidget {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
const _Card(this.text,
{required this.descriptionText,
this.icon = Icons.ac_unit_outlined,
this.imageUrl});
factory _Card.fromData(_CardData data) => _Card(
data.text,
descriptionText: data.descriptionText,
icon: data.icon,
imageUrl: data.imageUrl,
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.amber,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.grey,
width: 2,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
width: 140,
height: 100,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
2024-09-19 19:10:50 +04:00
),
2024-10-03 20:02:24 +04:00
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(text, style: Theme.of(context).textTheme.headlineLarge),
Text(descriptionText,
style: Theme.of(context).textTheme.bodyLarge),
],
2024-09-19 19:10:50 +04:00
),
2024-10-03 20:02:24 +04:00
)),
Padding(
padding: const EdgeInsets.only(left:8.0),
child: Icon(icon),
),
],
2024-09-19 19:10:50 +04:00
),
);
}
}