Last active
March 3, 2025 07:59
-
-
Save yamnikov-oleg/f49c98515422a46fa8038a999f735b49 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
// ЗАДАНИЕ: | |
// Перед вами нефункциональный черновик экрана с формой заказа. | |
// Попробуйте запустить его. | |
// По нажатию на кнопку "Отправить" форма должна отправлять запрос | |
// на бэкенд с помощью метода ApiClient.post. | |
// | |
// Завершите реализацию экрана с хорошим UX на ваше усмотрение. | |
// Допустимо сделать рефакторинг виджетов. | |
// Бонус: используйте в реализации пакет state management на ваш выбор | |
// (в dartpad все популярные пакеты предустановлены). | |
// | |
// ЗАДАНИЕ 2: | |
// В форму добавлено поле "Количество". У метода ApiClient.post изменился состав параметров. | |
// Под каждым полем формы дописаны правила валидации. | |
// Добавьте в форму валидацию ввода. Пользователю нельзя отправлять на бэкенд невалидный ввод. | |
import 'package:flutter/material.dart'; | |
class ApiClient { | |
Future<void> post({ | |
required String name, | |
String? address, | |
required int quantity, | |
}) async { | |
// post симулирует сетевой запрос. | |
// Будем считать, что эта функция - черный ящик. | |
await Future.delayed(const Duration(seconds: 3)); | |
} | |
} | |
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 FormScreen(), | |
); | |
} | |
} | |
class FormScreen extends StatelessWidget { | |
const FormScreen({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text("Заказ")), | |
body: SingleChildScrollView( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Column( | |
children: [ | |
const TextField( | |
decoration: InputDecoration( | |
label: Text("Полное имя"), | |
helperText: "Необязательно.", | |
), | |
), | |
const SizedBox(height: 16.0), | |
const TextField( | |
decoration: InputDecoration( | |
label: Text("Адрес"), | |
helperText: "Не меньше 2 символов.", | |
), | |
), | |
const SizedBox(height: 16.0), | |
const TextField( | |
decoration: InputDecoration( | |
label: Text("Количество"), | |
helperText: "Целое число. Минимум 1.", | |
), | |
), | |
const SizedBox(height: 16.0), | |
FilledButton(onPressed: () {}, child: const Text("Отправить")), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment