aman-kassa-flutter/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart

197 lines
6.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:aman_kassa_flutter/redux/actions/main_actions.dart';
import 'package:aman_kassa_flutter/redux/store.dart';
import 'package:aman_kassa_flutter/shared/app_colors.dart';
import 'package:aman_kassa_flutter/shared/ui_helpers.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class ProductAddBottomSheet extends StatefulWidget {
final ScrollController scrollController;
ProductAddBottomSheet({this.scrollController});
@override
_ProductAddBottomSheetState createState() => _ProductAddBottomSheetState();
}
class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
TextEditingController nameController;
TextEditingController countController;
TextEditingController priceController;
double sum = 0.0;
@override
void initState() {
// TODO: implement initState
super.initState();
nameController = new TextEditingController();
countController = new TextEditingController();
priceController = new TextEditingController();
}
@override
void dispose() {
nameController.dispose();
countController.dispose();
priceController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: whiteColor),
child: Scaffold(
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.black),
backgroundColor: fillColor,
elevation: 3,
title: Text(
'Добавить товар/услугу',
style: TextStyle(color: Colors.black87),
),
),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10),
child: ListView(
controller: widget.scrollController,
children: <Widget>[
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: primaryColor)),
hintText: 'Введите наименовение',
labelText: 'Наименование',
prefixText: ' ',
),
controller: nameController,
),
verticalSpaceSmall,
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: primaryColor)),
hintText: 'Введите количество',
labelText: 'Количество',
prefixText: ' ',
),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly
],
controller: countController,
onChanged: calcOnChange,
),
verticalSpaceSmall,
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: primaryColor)),
hintText: 'Введите цену за единицу',
labelText: 'Стоимость',
prefixText: ' ',
),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter(RegExp("^[0-9.]*")),
],
controller: priceController,
onChanged: calcOnChange,
),
const Divider(
height: 1.0,
),
new ListTile(
leading: const Icon(
Icons.account_balance_wallet,
color: primaryColor,
),
title: Text(sum == 0 ? '' : sum.toString()),
subtitle: const Text('Стоимость'),
),
verticalSpaceMedium,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
RawMaterialButton(
onPressed: submit,
elevation: 2.0,
fillColor: greenColor,
child: Icon(
Icons.done,
size: 35.0,
color: whiteColor,
),
padding: EdgeInsets.all(15.0),
shape: CircleBorder(),
),
RawMaterialButton(
onPressed: () {
Navigator.pop(context);
},
elevation: 2.0,
fillColor: redColor,
child: Icon(
Icons.close,
size: 35.0,
color: whiteColor,
),
padding: EdgeInsets.all(15.0),
shape: CircleBorder(),
)
],
)
],
),
),
),
);
}
void submit() {
if (nameController.text.isEmpty ||
countController.text.isEmpty ||
priceController.text.isEmpty) {
_showDialog();
} else {
Redux.store.dispatch(addCustomProductToKassaItems(nameController.text,
int.parse(countController.text), double.parse(priceController.text)));
Navigator.pop(context);
}
}
void calcOnChange(value) {
setState(() {
sum = 0;
});
double count = double.parse(countController.text);
double price = double.parse(priceController.text);
double result = count * price;
setState(() {
sum = ((result * 100).roundToDouble()) / 100;
});
}
void _showDialog() {
// flutter defined function
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text("Aman Касса"),
content: new Text("Введите наименова, количество и цену"),
actions: <Widget>[
new FlatButton(
child: new Text("ОK", style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}