Skip to content

Instantly share code, notes, and snippets.

@yamnikov-oleg
Last active February 26, 2025 05:39
Show Gist options
  • Save yamnikov-oleg/540da2ca784bdc90eb8d9648dbc19e2b to your computer and use it in GitHub Desktop.
Save yamnikov-oleg/540da2ca784bdc90eb8d9648dbc19e2b to your computer and use it in GitHub Desktop.
Flutter: Список товаров
// ЗАДАНИЕ:
// Реализуйте экран ProductListScreen, выводящий товары из списка products.
// Выведите для каждого товара название, описание и цену.
// Оформите UI по своему усмотрению.
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
class Product {
const Product({
required this.id,
required this.name,
required this.description,
required this.price,
});
final int id;
final String name;
final String description;
final int price;
}
// Выводим товары из этого сгенерированного списка.
final List<Product> products = List.generate(100, (index) {
final titlecase =
(String s) => "${s[0].toUpperCase()}${s.substring(1).toLowerCase()}";
final shuffledNouns = nouns.map(titlecase).toList();
shuffledNouns.shuffle();
return Product(
id: index,
name: shuffledNouns.take(5).join(" "),
description: shuffledNouns.skip(5).take(20).join(" "),
price: Random().nextInt(100) * 100 + 100,
);
});
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Список товаров',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorSchemeSeed: Colors.blue,
),
home: const ProductListScreen(),
);
}
}
class ProductListScreen extends StatelessWidget {
const ProductListScreen({super.key});
@override
Widget build(BuildContext context) {
// TODO: implement build
throw UnimplementedError();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment