171 lines
4.1 KiB
Dart
171 lines
4.1 KiB
Dart
import 'dart:math';
|
||
import 'package:flutter/material.dart';
|
||
// Classes +
|
||
// Methods +
|
||
// Enums +
|
||
// Loops +
|
||
// Generics (List<>) +
|
||
// Anonymous functions +
|
||
// Future +
|
||
// Extension +
|
||
|
||
void main() {
|
||
runApp(const MyApp());
|
||
}
|
||
|
||
class MyApp extends StatelessWidget {
|
||
const MyApp({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return MaterialApp(
|
||
title: 'Gerimovich demo',
|
||
theme: ThemeData(
|
||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
|
||
useMaterial3: true,
|
||
),
|
||
home: const MyHomePage(title: 'Gerimovich I M'),
|
||
);
|
||
}
|
||
}
|
||
|
||
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
|
||
void initState() {
|
||
super.initState();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||
title: Text(widget.title),
|
||
),
|
||
body: const StocksWidget(),
|
||
);
|
||
}
|
||
}
|
||
|
||
enum StockCategory { oilgas, finance, mining }
|
||
extension StockCategoryExtension on StockCategory {
|
||
String get name {
|
||
switch (this) {
|
||
case StockCategory.oilgas:
|
||
return 'Нефтегазовая отрасль';
|
||
case StockCategory.finance:
|
||
return 'Банки';
|
||
case StockCategory.mining:
|
||
return 'Добыча полезных ископаемых';
|
||
}
|
||
}
|
||
}
|
||
|
||
class Stock {
|
||
final String name;
|
||
final double price;
|
||
final String imageUrl;
|
||
final StockCategory category;
|
||
|
||
Stock({
|
||
required this.name,
|
||
required this.price,
|
||
required this.imageUrl,
|
||
required this.category,
|
||
});
|
||
}
|
||
|
||
class StocksWidget extends StatelessWidget {
|
||
const StocksWidget({super.key});
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
|
||
final stocks = [
|
||
Stock(
|
||
name: 'Алроса',
|
||
price: 52.90,
|
||
imageUrl:
|
||
'https://data.cbonds.info/organisations_logos/18/1617957662ALROSA_Rus_COLOUR_RGB.jpg',
|
||
category: StockCategory.mining),
|
||
Stock(
|
||
name: 'Газпром',
|
||
price: 135.43,
|
||
imageUrl: 'https://data.cbonds.info/organisations_logos/21/21.png',
|
||
category: StockCategory.oilgas),
|
||
Stock(
|
||
name: 'Сбербанк',
|
||
price: 257.50,
|
||
imageUrl:
|
||
'https://data.cbonds.info/organisations_logos/313/1615279834sberbank__2-01.png',
|
||
category: StockCategory.finance),
|
||
Stock(
|
||
name: 'Сбербанк',
|
||
price: 111111111.111111111,
|
||
imageUrl:
|
||
'https://data.cbonds.info/organisations_logos/313/1615279834sberbank__2-01.png',
|
||
category: StockCategory.finance),
|
||
];
|
||
|
||
return Center(
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
...stocks.map((e) => StockCard(stock: e)),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class StockCard extends StatelessWidget {
|
||
final Stock stock;
|
||
const StockCard({super.key, required this.stock});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Card(
|
||
margin: const EdgeInsets.all(8.0),
|
||
child: Padding(
|
||
padding: const EdgeInsets.all(14.0),
|
||
child: Row(
|
||
children: [
|
||
Image.network(
|
||
stock.imageUrl,
|
||
width: 85,
|
||
height: 85,
|
||
),
|
||
const SizedBox(width: 16.0),
|
||
Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
stock.name,
|
||
style: Theme.of(context).textTheme.headlineSmall,
|
||
),
|
||
Text(
|
||
'${stock.price.toStringAsFixed(2)} р',
|
||
style: Theme.of(context).textTheme.bodyLarge,
|
||
),
|
||
Text(
|
||
stock.category.name,
|
||
style: Theme.of(context).textTheme.bodySmall,
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|