Skip to content

Commit

Permalink
Merge pull request #79 from IQuinteros/developing
Browse files Browse the repository at this point in the history
Adding improvements and fixes
  • Loading branch information
IQuinteros authored Jun 26, 2021
2 parents f9826ae + 75a67a5 commit e1cad53
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 143 deletions.
6 changes: 5 additions & 1 deletion lib/providers/base_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class BaseAPI<T extends BaseModel>{
// Hosting: ecomercioweb.000webhostapp.com
static const String _authority = 'ecomercioweb.000webhostapp.com';//'localhost:8888';
static const String _requests = 'api/requests';
static const String _apiKey = 'iyinF635EHL7SF8cmYY6rR9en4uRQjA1';

final String baseUrl;
Map<String, dynamic> Function(T) getJsonParams;
Expand All @@ -40,10 +41,13 @@ abstract class BaseAPI<T extends BaseModel>{
if(DEBUG) print('processing ${jsonEncode(params)}');
if(DEBUG) print('Uri: $uri');
Response resp;

if(params == null) params = {};

try{
resp = await http.post(
uri,
body: jsonEncode(params),
body: jsonEncode(params..addAll({'C8AEA': _apiKey})),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
Expand Down
7 changes: 0 additions & 7 deletions lib/utils/email_util.dart

This file was deleted.

56 changes: 56 additions & 0 deletions lib/utils/text_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@


import 'package:intl/intl.dart';

class TextValidationUtil{

static bool validateEmail(String email) => RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(email);
static bool validateRut(String rut) => RegExp(r"^(\d{1,3}(?:\.\d{1,3}){2}-[\dkK])$").hasMatch(rut) && _validRutDv(rut);

static String stringToRut(String preRut){
if(preRut.isEmpty) return '';
if(preRut.length <= 1) return preRut;
if(preRut.length > 1){
if(preRut.length > 9) preRut = preRut.substring(0, 9);
if(preRut.indexOf('k') >= 0) preRut = preRut.substring(0, preRut.indexOf('k')+1);
String withoutDv = preRut.substring(0, preRut.length - 1);
final format = NumberFormat("##,###.###", "tr_TR");
String formattedWithoutDv = format.format(int.parse(withoutDv));
return formattedWithoutDv + preRut.replaceRange(preRut.length - 1, preRut.length, '-${preRut[preRut.length-1]}').substring(preRut.length - 1, preRut.length+1);
}
return preRut;
}

static int? getNumRutValue(String rut){
if(rut.isEmpty) return null;
if(rut.split('-').length < 2) return null;
final numberDotsString = rut.split('-')[0];
final numberString = numberDotsString.split('.').join();
print(numberString);
return int.tryParse(numberString);
}

static String? getDvRutValue(String rut){
if(rut.isEmpty) return null;
if(rut.split('-').length < 2) return null;
return rut.split('-')[1];
}

static bool _validRutDv(String rut){
if(rut.isEmpty) return false;
if(rut.split('-').length < 2) return false;
final numberDotsString = rut.split('-')[0];
final numberRevString = numberDotsString.split('.').join().split('').reversed.join();
List<int> results = [];
for (var i = 0; i < numberRevString.length; i++) {
int? number = int.tryParse(numberRevString[i]);
if(number == null) continue;

results.add(number * (i % 6 + 2));
}
final sum = results.reduce((value, element) => value + element);
final remainder = sum % 11;
final dv = (11 - remainder) == 10? 'k' : (11 - remainder) == 11? '0' : (11 - remainder).toString();
return rut.split('-')[1].toLowerCase() == dv;
}
}
7 changes: 6 additions & 1 deletion lib/views/article_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ class _ArticleAppBar extends StatelessWidget {
)
]
),
height: 80,
child: SafeArea(
child: Container(
height: 60
),
),
),
],
),
Expand Down Expand Up @@ -281,6 +285,7 @@ class _ArticleContent extends StatelessWidget {
final articleBloc = BlocProvider.of<ArticleBloc>(context);

articleBloc.getStoreOfArticle(article).then((value) {
if(_storeController.isClosed) return;
_storeSink(value);
disposeStreams();
});
Expand Down
12 changes: 8 additions & 4 deletions lib/views/cart_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ class _CartViewState extends State<CartView> {
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Aún no tienes artículos en tu carrito',
style: GoogleFonts.montserrat(),
textAlign: TextAlign.center,
SizedBox(width: 20.0,),
Expanded(
child: Text(
'Aún no tienes artículos en tu carrito',
style: GoogleFonts.montserrat(),
textAlign: TextAlign.center,
),
),
SizedBox(width: 20.0,),
],
)
);
Expand Down
4 changes: 2 additions & 2 deletions lib/views/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ class LoginView extends StatelessWidget {
onPressed: () => _tryLogin(context)
),
),
Container(
/* Container(
margin: EdgeInsets.only(
left: 40.0,
right: 40.0,
top: 20.0
),
child: GoogleButton(),
),
), */
SizedBox(height: 10.0,),
Divider(thickness: 1,),
Container(
Expand Down
134 changes: 68 additions & 66 deletions lib/views/new_opinion_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,74 +59,76 @@ class _NewOpinionViewState extends State<NewOpinionView> {
horizontal: 20.0,
vertical: 20.0
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_CoverOpinionInfo(articlePurchase: widget.articlePurchase),
SizedBox(height: 10.0),
Divider(thickness: 1,),
SizedBox(height: 20.0),
Text(
'Califica con estrellas',
style: GoogleFonts.montserrat(
fontWeight: FontWeight.w400,
fontSize: 18
),
textAlign: TextAlign.center,
),
SizedBox(height: 10.0),
Row(
children: [
Spacer(),
StarsRow(
rating: 0,
editable: true,
onEdit: (value) => stars = value.toInt(),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_CoverOpinionInfo(articlePurchase: widget.articlePurchase),
SizedBox(height: 10.0),
Divider(thickness: 1,),
SizedBox(height: 20.0),
Text(
'Califica con estrellas',
style: GoogleFonts.montserrat(
fontWeight: FontWeight.w400,
fontSize: 18
),
Spacer(),
],
),
SizedBox(height: 10.0),
Divider(thickness: 1,),
SizedBox(height: 20.0),
NormalInput(
header: '¿Qué te pareció el producto?',
hint: 'En pocas palabras',
icon: Icons.comment,
controller: titleController,
type: TextInputType.text,
maxLength: 50,
validator: (value) => value == null || value.isEmpty? 'Tu reseña necesita una pequeña opinión' : null,
),
NormalInput(
header: 'Detalles (opcional)',
hint: '',
icon: Icons.comment,
controller: commentController,
type: TextInputType.multiline,
maxLines: 5,
maxLength: 250,
),
SizedBox(height: 20.0),
NormalButton(
text: 'Enviar reseña',
onPressed: (){
final validate = _formKey.currentState!.validate();
if(stars <= 0){
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Antes, califica con estrellas por favor'),
backgroundColor: EcoAppColors.MAIN_DARK_COLOR,
));
return;
}
if(!validate) return;

textAlign: TextAlign.center,
),
SizedBox(height: 10.0),
Row(
children: [
Spacer(),
StarsRow(
rating: 0,
editable: true,
onEdit: (value) => stars = value.toInt(),
),
Spacer(),
],
),
SizedBox(height: 10.0),
Divider(thickness: 1,),
SizedBox(height: 20.0),
NormalInput(
header: '¿Qué te pareció el producto?',
hint: 'En pocas palabras',
icon: Icons.comment,
controller: titleController,
type: TextInputType.text,
maxLength: 50,
validator: (value) => value == null || value.isEmpty? 'Tu reseña necesita una pequeña opinión' : null,
),
NormalInput(
header: 'Detalles (opcional)',
hint: '',
icon: Icons.comment,
controller: commentController,
type: TextInputType.multiline,
maxLines: 5,
maxLength: 250,
),
SizedBox(height: 20.0),
NormalButton(
text: 'Enviar reseña',
onPressed: (){
final validate = _formKey.currentState!.validate();
if(stars <= 0){
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Antes, califica con estrellas por favor'),
backgroundColor: EcoAppColors.MAIN_DARK_COLOR,
));
return;
}
if(!validate) return;


sendOpinion(context);
}
)
],
sendOpinion(context);
}
)
],
),
),
)
),
Expand Down
21 changes: 17 additions & 4 deletions lib/views/profile_modify_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import 'dart:convert';
import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_ecoapp/bloc/district_bloc.dart';
import 'package:flutter_ecoapp/bloc/profile_bloc.dart';
import 'package:flutter_ecoapp/models/district.dart';
import 'package:flutter_ecoapp/models/profile.dart';
import 'package:flutter_ecoapp/utils/email_util.dart';
import 'package:flutter_ecoapp/utils/text_util.dart';
import 'package:flutter_ecoapp/views/profile_modify_pass_view.dart';
import 'package:flutter_ecoapp/views/style/colors.dart';
import 'package:flutter_ecoapp/views/widgets/district_input.dart';
Expand Down Expand Up @@ -200,12 +201,24 @@ class _ProfileModifyMainContent extends StatelessWidget {
},
),
NormalInput(
header: 'Teléfono - Celular',
hint: 'Ingresa tu número de contacto',
header: 'Celular',
hint: '912345678',
icon: Icons.phone,
type: TextInputType.phone,
controller: controllers['phone']!,
validator: (value) => value!.isEmpty? 'Debe ingresar su número de contacto' : null
validator: (value) {
if(value!.isEmpty)
return 'Debe ingresar su número de contacto';
if(value.length < 9)
return 'El número de contacto no es válido';
if(!value.startsWith('9'))
return 'El número debe comenzar con 9';
return null;
},
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
],
maxLength: 9,
),
NormalInput(
header: 'Fecha de nacimiento',
Expand Down
1 change: 1 addition & 0 deletions lib/views/purchase_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class _StoreList extends StatelessWidget {
price: e.unitPrice.toDouble(),
title: e.title,
extraTag: 'purchase-list-${e.id}',
requestRefresh: true,
onLongPress: (){
if(e.article != null){
showModalBottomSheet(
Expand Down
Loading

0 comments on commit e1cad53

Please sign in to comment.