import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', debugShowCheckedModeBanner: false, home: const MyHomePage(title: 'Чернышев Георгий Янович'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color.fromARGB(255, 46, 65, 80), appBar: AppBar( backgroundColor: Color.fromARGB(255, 56, 90, 128), title: Text( widget.title, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold), ), ), body: Container( //симметричный боковой отступ от границ экрана margin: const EdgeInsets.symmetric(horizontal: 15.0), child: const GameWidget(), ), ); } } class GameWidget extends StatelessWidget { const GameWidget({super.key}); @override Widget build(BuildContext context) { final data=[ _GameData( name: 'Late Shift', price: 399, image: 'https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/584980/capsule_616x353.jpg?t=1697110140'), _GameData( name: 'Dark Nights with Poe & Munro', price: 450, image: 'https://shared.akamai.steamstatic.com/store_item_assets/steam/apps/1098170/capsule_616x353.jpg?t=1725541685'), _GameData( name: 'Неизвестная игра', price: 999, ) ]; return Center( child: SingleChildScrollView( child: Column( children: data.map((e) => _GameCard.fromData(e)).toList()) ) ); } } class _GameData { final String name; final int price; final String? image; _GameData({ required this.name, required this.price, this.image='https://parpol.ru/wp-content/uploads/2019/09/placeholder.png'}); } class _GameCard extends StatelessWidget { final String name; final int price; final String? image; //обычный конструктор const _GameCard({ super.key, required this.name, required this.price, this.image, }); //именованный конструктор factory _GameCard.fromData(_GameData data) => _GameCard( name: data.name, price: data.price, image: data.image); @override Widget build(BuildContext context) { return Container( margin: const EdgeInsets.only(top: 10, bottom: 10), padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: const Color.fromARGB(255, 56, 90, 128), borderRadius: BorderRadius.circular(5), ), child: Column( //Выравнивание по середине crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( height: 200, width: MediaQuery.of(context).size.width, child: Image.network(image ?? '', fit: BoxFit.fill, errorBuilder: (_, __, ___) => const Placeholder()), ), // Название игры Text( name, style: const TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 32, ), textAlign: TextAlign.center, // softWrap: true, ), // Цена игры Text( '$price руб.', style: const TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 24, ), //softWrap: true, ), ], ) ); } } // class Game extends Object { // final String name; // final int price; // final GameType type; //жанр игры // final String? description; // // @override // bool operator ==(Object other) { // if (other is Game) { // return this.name == other.name; // } // return false; // } // // //стандартный конструктор с именованными параметрами // Game( // {required this.name, // required this.price, // required this.type, // this.description}); // // //именованный конструктор с примером игры // Game.exampleLateShift() // : name = 'Late Shift', // price = 200, // type = GameType.FMV, // description = null; // // void printInfo() { // print(''' // Игра: $name // Жанр: ${GameTypeNames[type]} // Цена: $price руб. '''); // if (description != null) { // print('Описание: $description'); // } // } // // //асинхронный метод - иммитация скачивания // Future download() async { // print('Начало загрузки игры $name'); // var rand = Random(); // int time = rand.nextInt(10000) + 100; // //асинхронность (Future), анонимная функция (Anonymous function) // await Future.delayed( // Duration(milliseconds: time), () => print("Игра $name загружена")); // } // } // // enum GameType { FMV, Shooter, Strategy, Horror } // // //Названия жанров на русском // const Map GameTypeNames = { // GameType.FMV: "FMV", // GameType.Shooter: "Шутер", // GameType.Strategy: "Стратегия", // GameType.Horror: "Хоррор" // }; // // void availableTypesRus() => printMapValues(GameTypeNames); // // //цикл (loop) + generic (хз, куда ещё их можно) // void printMapValues(Map map) { // for (var val in map.values) { // print(val); // } // } // // extension GameTypeRus on GameType { // String get rusName { // switch (this) { // case GameType.FMV: // return 'FMV'; // case GameType.Shooter: // return 'Шутер'; // case GameType.Strategy: // return 'Стратегия'; // case GameType.Horror: // return 'Хоррор'; // } // } // }