100 lines
3.3 KiB
Dart
100 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:satu/core/models/dictionary/contragent/contragent_response_entity.dart';
|
|
import 'package:satu/widgets/fields/line_tile.dart';
|
|
|
|
import '../../../../core/services/buy_service.dart';
|
|
import '../../../../core/services/navigator_service.dart';
|
|
import '../../../../core/utils/locator.dart';
|
|
import '../../../../routes/route_names.dart';
|
|
import '../../../../widgets/bar/products_app_bar.dart';
|
|
import '../../../../widgets/buttons/busy_button.dart';
|
|
|
|
class BuyAddView extends StatefulWidget {
|
|
const BuyAddView({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<BuyAddView> createState() => _BuyAddViewState();
|
|
}
|
|
|
|
class _BuyAddViewState extends State<BuyAddView> {
|
|
ContragentResponseEntity? _contragent;
|
|
DateTime _date = DateTime.now();
|
|
final BuyService _service = locator<BuyService>();
|
|
DateFormat _dateFormat = DateFormat('dd.MM.yyyy');
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: const ProductsAppBar(
|
|
title: 'Новая накладная покупки',
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView(
|
|
children: [
|
|
LineTile(
|
|
key: const Key('BuyAddView_Contragent'),
|
|
_contragent?.name ?? 'Выберите контрагента',
|
|
onTap: () async {
|
|
ContragentResponseEntity? entity =
|
|
await locator<NavigatorService>()
|
|
.push(contragentSelectViewRoute)
|
|
as ContragentResponseEntity?;
|
|
if (entity != null) {
|
|
setState(() {
|
|
_contragent = entity;
|
|
});
|
|
}
|
|
},
|
|
labelText: 'Контрагент',
|
|
),
|
|
LineTile(
|
|
key: const Key('BuyAddView_Date'),
|
|
_dateFormat.format(_date),
|
|
onTap: () async {
|
|
|
|
DateTime? pickedDate = await showDatePicker(
|
|
context: context,
|
|
initialDate: DateTime.now(), //get today's date
|
|
firstDate:DateTime(2000), //DateTime.now() - not to allow to choose before today.
|
|
lastDate: DateTime(2101)
|
|
);
|
|
if (pickedDate != null) {
|
|
setState(() {
|
|
_date = pickedDate;
|
|
});
|
|
}
|
|
|
|
},
|
|
labelText: 'Дата накладной',
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 45, vertical: 30),
|
|
child: BusyButton(
|
|
title: 'СОЗДАТЬ',
|
|
busy: false,
|
|
onPressed: () async {
|
|
|
|
if (_contragent == null) {
|
|
return;
|
|
}
|
|
|
|
|
|
bool result = await _service.createBuy(_contragent!, _date);
|
|
if (result) {
|
|
locator<NavigatorService>().pop(result);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|