Last active
February 11, 2025 04:30
-
-
Save yamnikov-oleg/d9111fe45b06d5e5c95459d26b825c30 to your computer and use it in GitHub Desktop.
Flutter: Отправка формы
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. | |
// | |
// Завершите реализацию экрана с хорошим UI/UX на ваше усмотрение. | |
// Допустимо сделать рефакторинг виджетов. | |
// Бонус: используйте в реализации пакет state management на ваш выбор | |
// (в dartpad все популярные пакеты предустановлены). | |
import 'package:flutter/material.dart'; | |
class ApiClient { | |
Future<void> post({required String name, 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: "Не меньше 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