242 lines
6.5 KiB
Dart
Raw Normal View History

2024-09-09 23:59:15 +04:00
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
2024-10-02 22:44:53 +04:00
@override
2024-09-09 23:59:15 +04:00
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
2024-09-10 00:10:35 +04:00
debugShowCheckedModeBanner: false,
2024-09-09 23:59:15 +04:00
home: const MyHomePage(title: 'Чернышев Георгий Янович'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
2024-10-02 22:44:53 +04:00
return Scaffold(
2024-10-13 20:04:40 +04:00
backgroundColor: Color.fromARGB(255, 46, 65, 80),
2024-09-09 23:59:15 +04:00
appBar: AppBar(
2024-10-13 20:04:40 +04:00
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(),
2024-09-09 23:59:15 +04:00
),
2024-10-03 00:05:26 +04:00
);
}
}
class GameWidget extends StatelessWidget {
const GameWidget({super.key});
@override
Widget build(BuildContext context) {
2024-10-13 20:04:40 +04:00
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,
)
];
2024-10-03 00:05:26 +04:00
return Center(
child: SingleChildScrollView(
2024-10-13 20:04:40 +04:00
child: Column(
children: data.map((e) => _GameCard.fromData(e)).toList())
)
2024-10-03 00:05:26 +04:00
);
}
}
2024-10-13 20:04:40 +04:00
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'});
}
2024-10-03 00:05:26 +04:00
class _GameCard extends StatelessWidget {
final String name;
final int price;
2024-10-13 20:04:40 +04:00
final String? image;
2024-10-03 00:05:26 +04:00
2024-10-13 20:04:40 +04:00
//обычный конструктор
2024-10-03 00:05:26 +04:00
const _GameCard({
2024-10-13 20:04:40 +04:00
super.key,
required this.name,
required this.price,
this.image,
2024-10-03 00:05:26 +04:00
});
2024-10-13 20:04:40 +04:00
//именованный конструктор
factory _GameCard.fromData(_GameData data) => _GameCard(
name: data.name,
price: data.price,
image: data.image);
2024-10-03 00:05:26 +04:00
@override
Widget build(BuildContext context) {
2024-10-13 20:04:40 +04:00
2024-10-03 00:05:26 +04:00
return Container(
2024-10-13 20:04:40 +04:00
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,
2024-10-03 00:05:26 +04:00
),
2024-10-13 20:04:40 +04:00
textAlign: TextAlign.center,
// softWrap: true,
),
// Цена игры
Text(
'$price руб.',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24,
2024-10-03 00:05:26 +04:00
),
2024-10-13 20:04:40 +04:00
//softWrap: true,
),
],
)
);
2024-10-02 22:44:53 +04:00
}
}
2024-10-13 20:04:40 +04:00
// 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<void> 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<GameType, String> GameTypeNames = {
// GameType.FMV: "FMV",
// GameType.Shooter: "Шутер",
// GameType.Strategy: "Стратегия",
// GameType.Horror: "Хоррор"
// };
//
// void availableTypesRus() => printMapValues(GameTypeNames);
//
// //цикл (loop) + generic (хз, куда ещё их можно)
// void printMapValues<T, U>(Map<T, U> 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 'Хоррор';
// }
// }
// }