This commit is contained in:
sardq 2024-10-03 20:02:24 +04:00
parent f296e54a0f
commit 36585b7207

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -55,71 +56,127 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; final Color _color = Colors.blueAccent;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center( body: const MyWidget(),
// Center is a layout widget. It takes a single child and positions it );
// in the middle of the parent. }
child: Column( }
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its class MyWidget extends StatelessWidget {
// children horizontally, and tries to be as tall as its parent. const MyWidget({super.key});
//
// Column has various properties to control how it sizes itself and @override
// how it positions its children. Here we use mainAxisAlignment to Widget build(BuildContext context) {
// center the children vertically; the main axis here is the vertical final data = [
// axis because Columns are vertical (the cross axis would be _CardData(
// horizontal). 'Зов Ктулху',
// descriptionText: 'Лучше бы не находить разгадку, объединяющую сошедших с ума творцов...',
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" imageUrl: 'https://lovecraft.country/images/bibliography/call-of-cthulhu-mini.webp'
// action in the IDE, or press "p" in the console), to see the ),
// wireframe for each widget. _CardData(
mainAxisAlignment: MainAxisAlignment.center, 'Хребты безумия',
children: <Widget>[ descriptionText: '«Хребты безумия» написаны в документальной манере повествования, постепенно привыкая к которой, становишься свидетелем особой реальности описываемых событий.',
const Text( icon: Icons.hail,
'You have pushed the button this many times:', imageUrl: 'https://lovecraft.country/images/bibliography/At-the-Mountains-of-Madness-mini.webp'
), ),
Text( _CardData('Тень над Инсмутом', descriptionText: 'Инсмут, маленький рыбацкий городок неподалеку от Аркхэма, уже много лет имеет дурную славу. В округе ходят жуткие истории о его угрюмых и уродливых жителях, от которых лучше держаться подальше.', icon: Icons.warning_amber, imageUrl: 'https://lovecraft.country/images/bibliography/The-Shadow-over-Innsmouth.webp')
'$_counter', ];
style: Theme.of(context).textTheme.headlineMedium, return Center(
), child: SingleChildScrollView(
], child: Column(
), mainAxisAlignment: MainAxisAlignment.center,
), children: data.map((e) => _Card.fromData(e)).toList(),
floatingActionButton: FloatingActionButton( ),
onPressed: _incrementCounter, ),
tooltip: 'Increment', );
child: const Icon(Icons.add), }
), // This trailing comma makes auto-formatting nicer for build methods. }
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(),
),
),
),
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),
],
),
)),
Padding(
padding: const EdgeInsets.only(left:8.0),
child: Icon(icon),
),
],
),
); );
} }
} }