2024-09-09 23:59:15 +04:00
|
|
|
|
import 'package:flutter/material.dart';
|
2024-10-02 22:44:53 +04:00
|
|
|
|
import 'dart:math';
|
2024-09-09 23:59:15 +04:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
theme: ThemeData(
|
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.cyan),
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
),
|
|
|
|
|
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-09-09 23:59:15 +04:00
|
|
|
|
appBar: AppBar(
|
2024-10-02 22:44:53 +04:00
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
|
title: Text(widget.title),
|
2024-09-09 23:59:15 +04:00
|
|
|
|
),
|
2024-10-03 00:05:26 +04:00
|
|
|
|
body: const GameWidget(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class GameWidget extends StatelessWidget {
|
|
|
|
|
const GameWidget({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
_GameCard(name: 'Late Shift', price: 399,),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _GameCard extends StatelessWidget {
|
|
|
|
|
final String name;
|
|
|
|
|
final int price;
|
|
|
|
|
// final GameType type;
|
|
|
|
|
// final String? description;
|
|
|
|
|
//для image можно задать default значение (через = в констркуторе)
|
|
|
|
|
// final String image;
|
|
|
|
|
|
|
|
|
|
const _GameCard({
|
|
|
|
|
super.key, required this.name, required this.price,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// const _GameCard({
|
|
|
|
|
// super.key, required this.name, required this.price, required this.type, this.description, required this.image,
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
margin: const EdgeInsets.only(top: 16),
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.lightBlue,
|
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
|
),
|
|
|
|
|
child:
|
|
|
|
|
//ПЫТАЕТСЯ РАСТЯНУТЬСЯ НА ВЕСЬ ЭКРАН, ИСПРАВИТЬ
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
//ЗДЕСЬ ДО СТОЛБЦА БУДЕТ ФОТО (ОНО ДОЛЖНО БЫТЬ СЛЕВА)
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
//название игры
|
|
|
|
|
Text(
|
|
|
|
|
name,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
//цена игры
|
|
|
|
|
Text(
|
|
|
|
|
price.toString()+' руб.',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2024-09-09 23:59:15 +04:00
|
|
|
|
),
|
|
|
|
|
],
|
2024-10-03 00:05:26 +04:00
|
|
|
|
));
|
2024-10-02 22:44:53 +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)
|
|
|
|
|
Future.delayed(
|
|
|
|
|
Duration(milliseconds: time), () => print("Игра $name загружена"));
|
2024-09-09 23:59:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-02 22:44:53 +04:00
|
|
|
|
|
|
|
|
|
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 {
|
2024-10-03 00:05:26 +04:00
|
|
|
|
switch (this) {
|
2024-10-02 22:44:53 +04:00
|
|
|
|
case GameType.FMV:
|
|
|
|
|
return 'FMV';
|
|
|
|
|
case GameType.Shooter:
|
|
|
|
|
return 'Шутер';
|
|
|
|
|
case GameType.Strategy:
|
|
|
|
|
return 'Стратегия';
|
|
|
|
|
case GameType.Horror:
|
|
|
|
|
return 'Хоррор';
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 00:05:26 +04:00
|
|
|
|
}
|