lab2 n 3 aye say gang
This commit is contained in:
parent
9f7d39cc81
commit
bf3a31379d
@ -1,4 +1,4 @@
|
||||
# flutter_project
|
||||
# flutter_project by Gerimovich PIbd-32
|
||||
|
||||
A new Flutter project.
|
||||
|
||||
|
161
lib/main.dart
161
lib/main.dart
@ -1,4 +1,13 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
// Classes +
|
||||
// Methods +
|
||||
// Enums +
|
||||
// Loops +
|
||||
// Generics (List<>) +
|
||||
// Anonymous functions +
|
||||
// Future +
|
||||
// Extension +
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -7,25 +16,21 @@ void main() {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
title: 'Gerimovich demo',
|
||||
theme: ThemeData(
|
||||
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
home: const MyHomePage(title: 'Gerimovich I M'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
@ -33,39 +38,133 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
});
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
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,
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), );
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user