Last active
February 26, 2025 05:39
-
-
Save yamnikov-oleg/df23d76e161b6810f54701e19c5d51c3 to your computer and use it in GitHub Desktop.
Flutter: Список товаров 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ЗАДАНИЕ: | |
// Реализуйте экран ProductListScreen, выводящий товары из списка products. | |
// Выведите для каждого товара название, описание и цену. | |
// Оформите UI по своему усмотрению. | |
// | |
// ЗАДАНИЕ 2: | |
// Добавьте экран товара, который открывается по тапу на товар в списке. | |
// Бонус: используйте пакет роутинга (go_router или auto_router) на свой выбор. | |
// (В dartpad все популярные пакеты предустановлены.) | |
// | |
// Кроме задания 2 изменений в этом файле нет. | |
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