From fde7f54b2c444b10a341d22d99cc9271b02a4a3a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 12 Jun 2018 11:18:41 -0700 Subject: [PATCH] Refactor --- lib/ui/app/form_card.dart | 23 +++ lib/ui/app/progress_button.dart | 2 +- lib/ui/auth/login.dart | 129 +++++++------- lib/ui/client/edit/client_edit.dart | 2 +- .../edit/client_edit_billing_address.dart | 3 +- lib/ui/client/edit/client_edit_contacts.dart | 4 +- lib/ui/client/edit/client_edit_details.dart | 3 +- .../edit/client_edit_shipping_address.dart | 3 +- lib/ui/client/view/client_view_overview.dart | 4 +- lib/ui/product/product_edit.dart | 158 +++++++++--------- 10 files changed, 172 insertions(+), 159 deletions(-) create mode 100644 lib/ui/app/form_card.dart diff --git a/lib/ui/app/form_card.dart b/lib/ui/app/form_card.dart new file mode 100644 index 000000000..a9db43570 --- /dev/null +++ b/lib/ui/app/form_card.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class FormCard extends StatelessWidget { + FormCard({this.children}); + final List children; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(12.0), + child: Card( + elevation: 2.0, + child: Padding( + padding: const EdgeInsets.only( + left: 16.0, right: 16.0, top: 16.0, bottom: 20.0), + child: Column( + children: children, + ), + ), + ), + ); + } +} diff --git a/lib/ui/app/progress_button.dart b/lib/ui/app/progress_button.dart index 5c64f72b4..fbb6d2565 100644 --- a/lib/ui/app/progress_button.dart +++ b/lib/ui/app/progress_button.dart @@ -23,7 +23,7 @@ class ProgressButton extends StatelessWidget { */ return Padding( - padding: EdgeInsets.only(top: 20.0), + padding: EdgeInsets.only(left: 14.0, right: 14.0, top: 2.0), child: this.isLoading ? SizedBox( width: 100.0, diff --git a/lib/ui/auth/login.dart b/lib/ui/auth/login.dart index b0a3218fc..792d07ad0 100644 --- a/lib/ui/auth/login.dart +++ b/lib/ui/auth/login.dart @@ -3,6 +3,8 @@ import 'package:invoiceninja/redux/auth/auth_state.dart'; import 'package:invoiceninja/ui/app/progress_button.dart'; import 'package:invoiceninja/utils/localization.dart'; +import '../app/form_card.dart'; + class Login extends StatelessWidget { final bool isLoading; final bool isDirty; @@ -36,81 +38,77 @@ class Login extends StatelessWidget { return ListView( shrinkWrap: true, - padding: EdgeInsets.only(left: 12.0, right: 12.0, top: 20.0), - children: [ + children: [ Padding( padding: EdgeInsets.only(top: 20.0, bottom: 20.0), child: new Image.asset('assets/images/logo.png', width: 100.0, height: 100.0), ), - Card( - elevation: 2.0, - margin: EdgeInsets.all(0.0), - child: Form( - key: _formKey, - child: Container( - padding: EdgeInsets.all(16.0), - child: Column( - children: [ - TextFormField( - key: _emailKey, - initialValue: authState.email, - autocorrect: false, - decoration: InputDecoration(labelText: AppLocalization.of(context).email), - keyboardType: TextInputType.emailAddress, - validator: (val) => val.isEmpty || val.trim().length == 0 - ? AppLocalization.of(context).pleaseEnterYourEmail - : null, - ), - TextFormField( - key: _passwordKey, - initialValue: authState.password, - autocorrect: false, - decoration: InputDecoration(labelText: AppLocalization.of(context).password), - validator: (val) => val.isEmpty || val.trim().length == 0 - ? AppLocalization.of(context).pleaseEnterYourPassword - : null, - obscureText: true, - ), - TextFormField( - key: _urlKey, - initialValue: authState.url, - autocorrect: false, - decoration: InputDecoration(labelText: AppLocalization.of(context).url), - validator: (val) => val.isEmpty || val.trim().length == 0 - ? AppLocalization.of(context).pleaseEnterYourUrl - : null, - keyboardType: TextInputType.url, - ), - TextFormField( - key: _secretKey, - initialValue: authState.secret, - autocorrect: false, - decoration: InputDecoration(labelText: AppLocalization.of(context).secret), - /* + Form( + key: _formKey, + child: FormCard( + children: [ + TextFormField( + key: _emailKey, + initialValue: authState.email, + autocorrect: false, + decoration: InputDecoration( + labelText: AppLocalization.of(context).email), + keyboardType: TextInputType.emailAddress, + validator: (val) => val.isEmpty || val.trim().length == 0 + ? AppLocalization.of(context).pleaseEnterYourEmail + : null, + ), + TextFormField( + key: _passwordKey, + initialValue: authState.password, + autocorrect: false, + decoration: InputDecoration( + labelText: AppLocalization.of(context).password), + validator: (val) => val.isEmpty || val.trim().length == 0 + ? AppLocalization.of(context).pleaseEnterYourPassword + : null, + obscureText: true, + ), + TextFormField( + key: _urlKey, + initialValue: authState.url, + autocorrect: false, + decoration: + InputDecoration(labelText: AppLocalization.of(context).url), + validator: (val) => val.isEmpty || val.trim().length == 0 + ? AppLocalization.of(context).pleaseEnterYourUrl + : null, + keyboardType: TextInputType.url, + ), + TextFormField( + key: _secretKey, + initialValue: authState.secret, + autocorrect: false, + decoration: InputDecoration( + labelText: AppLocalization.of(context).secret), + /* validator: (val) => val.isEmpty || val.trim().length == 0 ? AppLocalization.of(context).pleaseEnterYourPassword : null, */ - obscureText: true, - ), - authState.error == null - ? Container() - : Container( - padding: EdgeInsets.only(top: 26.0, bottom: 4.0), - child: Center( - child: Text( - authState.error, - style: TextStyle( - color: Colors.red, - fontWeight: FontWeight.bold, - ), - ), + obscureText: true, + ), + authState.error == null + ? Container() + : Container( + padding: EdgeInsets.only(top: 26.0, bottom: 4.0), + child: Center( + child: Text( + authState.error, + style: TextStyle( + color: Colors.red, + fontWeight: FontWeight.bold, ), ), - ], - ), - ), + ), + ), + ], ), ), ProgressButton( @@ -122,7 +120,8 @@ class Login extends StatelessWidget { return; } - this.onLoginClicked(context, + this.onLoginClicked( + context, _emailKey.currentState.value, _passwordKey.currentState.value, _urlKey.currentState.value, diff --git a/lib/ui/client/edit/client_edit.dart b/lib/ui/client/edit/client_edit.dart index 51fde4935..c3363ca91 100644 --- a/lib/ui/client/edit/client_edit.dart +++ b/lib/ui/client/edit/client_edit.dart @@ -110,7 +110,7 @@ class _ClientEditState extends State ), ), body: Padding( - padding: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(16.0), child: Form( key: _formKey, child: TabBarView( diff --git a/lib/ui/client/edit/client_edit_billing_address.dart b/lib/ui/client/edit/client_edit_billing_address.dart index 20f76a5da..01e2a41da 100644 --- a/lib/ui/client/edit/client_edit_billing_address.dart +++ b/lib/ui/client/edit/client_edit_billing_address.dart @@ -39,8 +39,7 @@ class ClientEditBillingAddressState extends State Card( elevation: 2.0, child: Padding( - padding: const EdgeInsets.only( - left: 12.0, right: 12.0, top: 12.0, bottom: 18.0), + padding: const EdgeInsets.all(16.0), child: Column( children: [ TextFormField( diff --git a/lib/ui/client/edit/client_edit_contacts.dart b/lib/ui/client/edit/client_edit_contacts.dart index 39617114c..8bff85f8b 100644 --- a/lib/ui/client/edit/client_edit_contacts.dart +++ b/lib/ui/client/edit/client_edit_contacts.dart @@ -75,7 +75,7 @@ class ClientEditContactsState extends State } items.add(Padding( - padding: const EdgeInsets.all(12.0), + padding: const EdgeInsets.all(16.0), child: RaisedButton( elevation: 4.0, color: Theme.of(context).primaryColor, @@ -151,7 +151,7 @@ class ContactEditDetailsState extends State { child: Card( elevation: 2.0, child: Padding( - padding: const EdgeInsets.all(12.0), + padding: const EdgeInsets.all(16.0), child: Column( children: [ TextFormField( diff --git a/lib/ui/client/edit/client_edit_details.dart b/lib/ui/client/edit/client_edit_details.dart index d4604071d..869338d95 100644 --- a/lib/ui/client/edit/client_edit_details.dart +++ b/lib/ui/client/edit/client_edit_details.dart @@ -39,8 +39,7 @@ class ClientEditDetailsState extends State Card( elevation: 2.0, child: Padding( - padding: const EdgeInsets.only( - left: 12.0, right: 12.0, top: 12.0, bottom: 18.0), + padding: const EdgeInsets.all(16.0), child: Column( children: [ TextFormField( diff --git a/lib/ui/client/edit/client_edit_shipping_address.dart b/lib/ui/client/edit/client_edit_shipping_address.dart index 1e96685c8..6945791b9 100644 --- a/lib/ui/client/edit/client_edit_shipping_address.dart +++ b/lib/ui/client/edit/client_edit_shipping_address.dart @@ -38,8 +38,7 @@ class ClientEditShippingAddressState extends State Card( elevation: 2.0, child: Padding( - padding: const EdgeInsets.only( - left: 12.0, right: 12.0, top: 12.0, bottom: 18.0), + padding: const EdgeInsets.all(16.0), child: Column( children: [ TextFormField( diff --git a/lib/ui/client/view/client_view_overview.dart b/lib/ui/client/view/client_view_overview.dart index 92f2f62d7..f79535784 100644 --- a/lib/ui/client/view/client_view_overview.dart +++ b/lib/ui/client/view/client_view_overview.dart @@ -66,11 +66,11 @@ class ClientOverview extends StatelessWidget { return Column( children: [ Padding( - padding: EdgeInsets.all(12.0), + padding: EdgeInsets.all(16.0), child: Card( elevation: 2.0, child: Padding( - padding: EdgeInsets.all(12.0), + padding: EdgeInsets.all(16.0), child: _headerRow(), ), ), diff --git a/lib/ui/product/product_edit.dart b/lib/ui/product/product_edit.dart index fd0bf66a0..6734e576d 100644 --- a/lib/ui/product/product_edit.dart +++ b/lib/ui/product/product_edit.dart @@ -5,9 +5,9 @@ import 'package:invoiceninja/ui/app/progress_button.dart'; import 'package:invoiceninja/ui/product/product_edit_vm.dart'; import 'package:invoiceninja/utils/localization.dart'; +import '../app/form_card.dart'; class ProductEdit extends StatefulWidget { - final ProductEditVM viewModel; static final GlobalKey formKey = GlobalKey(); @@ -16,7 +16,6 @@ class ProductEdit extends StatefulWidget { @required this.viewModel, }) : super(key: key); - @override _ProductEditState createState() => _ProductEditState(); } @@ -36,90 +35,85 @@ class _ProductEditState extends State { ? AppLocalization.of(context).newProduct : viewModel .product.productKey), // Text(localizations.productDetails), - actions: viewModel.product.id == null ? [] : [ - ActionMenuButton( - entity: viewModel.product, - onSelected: viewModel.onActionSelected, - )], + actions: viewModel.product.id == null + ? [] + : [ + ActionMenuButton( + entity: viewModel.product, + onSelected: viewModel.onActionSelected, + ) + ], ), - body: Padding( - padding: EdgeInsets.all(16.0), - child: ListView(children: [ - Card( - elevation: 2.0, - margin: EdgeInsets.all(0.0), - child: Form( - key: ProductEdit.formKey, - child: Container( - padding: EdgeInsets.all(16.0), - child: Column( - children: [ - TextFormField( - autocorrect: false, - onSaved: (value) { - _productKey = value; - }, - initialValue: viewModel.product.productKey, - decoration: InputDecoration( - //border: InputBorder.none, - labelText: AppLocalization.of(context).product, - ), - validator: (val) => val.isEmpty || val.trim().length == 0 - ? AppLocalization.of(context).pleaseEnterAProductKey - : null, - ), - TextFormField( - initialValue: viewModel.product.notes, - onSaved: (value) { - print('onSaved: setting _notes to: ' + value); - _notes = value; - }, - maxLines: 4, - decoration: InputDecoration( - labelText: AppLocalization.of(context).notes, - ), - ), - TextFormField( - initialValue: viewModel.product.cost == null || - viewModel.product.cost == 0.0 - ? null - : viewModel.product.cost.toStringAsFixed(2), - onSaved: (value) { - _cost = double.tryParse(value) ?? 0.0; - }, - keyboardType: TextInputType.number, - decoration: InputDecoration( - //border: InputBorder.none, - labelText: AppLocalization.of(context).cost, - ), - ), - ], + body: Form( + child: ListView( + children: [ + FormCard( + children: [ + TextFormField( + autocorrect: false, + onSaved: (value) { + _productKey = value; + }, + initialValue: viewModel.product.productKey, + decoration: InputDecoration( + //border: InputBorder.none, + labelText: AppLocalization.of(context).product, + ), + validator: (val) => val.isEmpty || val.trim().length == 0 + ? AppLocalization.of(context).pleaseEnterAProductKey + : null, ), - ), + TextFormField( + initialValue: viewModel.product.notes, + onSaved: (value) { + print('onSaved: setting _notes to: ' + value); + _notes = value; + }, + maxLines: 4, + decoration: InputDecoration( + labelText: AppLocalization.of(context).notes, + ), + ), + TextFormField( + initialValue: viewModel.product.cost == null || + viewModel.product.cost == 0.0 + ? null + : viewModel.product.cost.toStringAsFixed(2), + onSaved: (value) { + _cost = double.tryParse(value) ?? 0.0; + }, + keyboardType: TextInputType.number, + decoration: InputDecoration( + //border: InputBorder.none, + labelText: AppLocalization.of(context).cost, + ), + ), + ], ), - ), - new Builder(builder: (BuildContext context) { - return viewModel.product.isDeleted == true - ? Container() - : ProgressButton( - label: AppLocalization.of(context).save.toUpperCase(), - isLoading: viewModel.isLoading, - isDirty: viewModel.isDirty, - onPressed: () { - if (! ProductEdit.formKey.currentState.validate()) { - return; - } - ProductEdit.formKey.currentState.save(); + new Builder(builder: (BuildContext context) { + return viewModel.product.isDeleted == true + ? Container() + : ProgressButton( + label: AppLocalization.of(context).save.toUpperCase(), + isLoading: viewModel.isLoading, + isDirty: viewModel.isDirty, + onPressed: () { + if (!ProductEdit.formKey.currentState.validate()) { + return; + } + ProductEdit.formKey.currentState.save(); - viewModel.onSaveClicked(context, - viewModel.product.rebuild((b) => b - ..productKey = _productKey - ..notes = _notes - ..cost = _cost)); - }, - ); - }), - ]), + viewModel.onSaveClicked( + context, + viewModel.product.rebuild((b) => b + ..productKey = _productKey + ..notes = _notes + ..cost = _cost)); + }, + ); + }), + ], + ), ), /* floatingActionButton: FloatingActionButton(