Refactor
This commit is contained in:
parent
1d1f173d8b
commit
fde7f54b2c
|
|
@ -0,0 +1,23 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class FormCard extends StatelessWidget {
|
||||
FormCard({this.children});
|
||||
final List<Widget> 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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: <Widget>[
|
||||
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: <Widget>[
|
||||
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: <Widget>[
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class _ClientEditState extends State<ClientEdit>
|
|||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: TabBarView(
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ class ClientEditBillingAddressState extends State<ClientEditBillingAddress>
|
|||
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: <Widget>[
|
||||
TextFormField(
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class ClientEditContactsState extends State<ClientEditContacts>
|
|||
}
|
||||
|
||||
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<ContactEditDetails> {
|
|||
child: Card(
|
||||
elevation: 2.0,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ class ClientEditDetailsState extends State<ClientEditDetails>
|
|||
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: <Widget>[
|
||||
TextFormField(
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ class ClientEditShippingAddressState extends State<ClientEditShippingAddress>
|
|||
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: <Widget>[
|
||||
TextFormField(
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ class ClientOverview extends StatelessWidget {
|
|||
return Column(
|
||||
children: <Widget>[
|
||||
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(),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
|
|
@ -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<ProductEdit> {
|
|||
? 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: <Widget>[
|
||||
FormCard(
|
||||
children: <Widget>[
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue