Initial commit
This commit is contained in:
144
lib/screens/aboutESMS.dart
Normal file
144
lib/screens/aboutESMS.dart
Normal file
@ -0,0 +1,144 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
class AboutScr extends StatefulWidget {
|
||||
@override
|
||||
_AboutScrState createState() => _AboutScrState();
|
||||
}
|
||||
|
||||
class _AboutScrState extends State<AboutScr> {
|
||||
PackageInfo p;
|
||||
String os;
|
||||
Future<bool> loaded;
|
||||
|
||||
Timer stuck;
|
||||
Future<bool> loadVals() async {
|
||||
if(Platform.isAndroid)
|
||||
os = "Android";
|
||||
else if(Platform.isIOS)
|
||||
os = "IOS";
|
||||
os += ' ${Platform.operatingSystemVersion}';
|
||||
|
||||
await PackageInfo.fromPlatform().then((value) {
|
||||
p = value;
|
||||
});
|
||||
return true && p != null;
|
||||
}
|
||||
|
||||
_reload() {
|
||||
stuck = Timer(Duration(seconds: 2), () {
|
||||
loaded = loadVals();
|
||||
stuck.cancel();
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = loadVals();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Sobre"),
|
||||
),
|
||||
body: _layout(),
|
||||
);
|
||||
}
|
||||
|
||||
_layout() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (p != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 8,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
color: Colors.redAccent[700],
|
||||
fontSize: 12,
|
||||
letterSpacing: 10),
|
||||
text: "RELEASE ${p.version}",),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w100,
|
||||
color: Colors.black,
|
||||
fontSize: 100),
|
||||
text: "ESMS"),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.black,
|
||||
fontSize: 12),
|
||||
text: "Eletronics Servicing Management System"),
|
||||
),
|
||||
Divider(
|
||||
color: Colors.black38,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 20),
|
||||
text:
|
||||
"Informações da Versão"),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Divider(color: Colors.transparent,),
|
||||
Text("Versão: ${p.version}"),
|
||||
Text("Número da Build: ${p.buildNumber}"),
|
||||
Text("Nome da Package: ${p.packageName}"),
|
||||
Text("Versão Dart: ${Platform.version.substring(0,Platform.version.lastIndexOf('(dev)'))}"),
|
||||
Text("Edição ${os}")
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
),
|
||||
Divider(color: Colors.transparent,),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text("Desenvolvido por F. Raszeja, 2021")
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
if (snapshot.data == false) {
|
||||
_reload();
|
||||
}
|
||||
return Container(
|
||||
child: Text("Oops!"),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
215
lib/screens/alterClient.dart
Normal file
215
lib/screens/alterClient.dart
Normal file
@ -0,0 +1,215 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:esms_project/client.dart';
|
||||
import 'package:esms_project/screens/listClients.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:esms_project/widgets/widget_input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'clientDetail.dart';
|
||||
|
||||
class alterClient extends StatefulWidget {
|
||||
Client c;
|
||||
|
||||
alterClient(this.c);
|
||||
@override
|
||||
_alterClientState createState() => _alterClientState();
|
||||
}
|
||||
|
||||
class _alterClientState extends State<alterClient> {
|
||||
Timer d;
|
||||
final values = new List<TextEditingController>.generate(
|
||||
4, (_) => TextEditingController());
|
||||
final _formCli = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
values[0].text = widget.c.name;
|
||||
values[1].text = widget.c.telephone;
|
||||
values[2].text = widget.c.cellular;
|
||||
values[3].text = widget.c.observations;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if (mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Alterar Cliente"),
|
||||
),
|
||||
body: _layout());
|
||||
}
|
||||
|
||||
_layout() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
height: double.infinity,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Form(
|
||||
key: _formCli,
|
||||
child: Column(
|
||||
children: [
|
||||
InputValidado(
|
||||
"Digite o nome do Cliente",
|
||||
"Ex. João da Silva",
|
||||
controller: values[0],
|
||||
),
|
||||
InputTextosPhone(
|
||||
"Digite um telefone",
|
||||
"Ex. (15) 1234-5678",
|
||||
controller: values[1],
|
||||
),
|
||||
InputTextosPhone(
|
||||
"Digite um celular",
|
||||
"Ex. (15) 991234-5678",
|
||||
controller: values[2],
|
||||
),
|
||||
InputTextos(
|
||||
"Observações:",
|
||||
"Ex. Tem (15) 99123-4567 como outro número celular",
|
||||
controller: values[3],
|
||||
),
|
||||
],
|
||||
)),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
Botoes(
|
||||
"Atualizar cliente",
|
||||
onPressed: _updateClient,
|
||||
),
|
||||
Botoes(
|
||||
"Remover cliente",
|
||||
onPressed: () {
|
||||
_removeClient();
|
||||
},
|
||||
)
|
||||
]
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
_updateClient() {
|
||||
setState(() {
|
||||
if (_formCli.currentState.validate()) {
|
||||
int temp = widget.c.id;
|
||||
widget.c = new Client(
|
||||
values[0].text,
|
||||
values[1].text,
|
||||
values[2].text,
|
||||
values[3].text,
|
||||
);
|
||||
widget.c.UpdateDB(temp);
|
||||
int StuckCount = 0;
|
||||
d = Timer(Duration(milliseconds: 300), () {
|
||||
if (widget.c.status == 1) {
|
||||
_showcontent(temp);
|
||||
StuckCount = 0;
|
||||
d.cancel();
|
||||
}
|
||||
else
|
||||
StuckCount++;
|
||||
});
|
||||
if (StuckCount >= 2)
|
||||
_displaySnackbar("Verifique os valores");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_displaySnackbar(String text) {
|
||||
setState(() {
|
||||
final snackBar =
|
||||
SnackBar(content: Text(text, style: TextStyle(fontSize: 16)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
}
|
||||
|
||||
void _showcontent(temp) {
|
||||
setState(() {
|
||||
showDialog(
|
||||
context: context, barrierDismissible: false, // user must tap button!
|
||||
|
||||
builder: (BuildContext context) {
|
||||
return new AlertDialog(
|
||||
title: new Text('Aviso'),
|
||||
content: new SingleChildScrollView(
|
||||
child: new ListBody(
|
||||
children: [
|
||||
new Text('Cliente atualizado.'),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
new TextButton(
|
||||
child: new Text('OK'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
if(values[0].text == "CLIENTE_REMOVIDO")
|
||||
Navigator.of(context).push(new MaterialPageRoute(
|
||||
builder: (context) => ListClients()));
|
||||
else {
|
||||
Navigator.of(context).push(new MaterialPageRoute(
|
||||
builder: (context) => ListClients()));
|
||||
Navigator.of(context).push(new MaterialPageRoute(
|
||||
builder: (context) => ClientDetail(temp)));
|
||||
}
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_removeClient() {
|
||||
setState(() {
|
||||
showDialog(
|
||||
context: context, barrierDismissible: false, // user must tap button!
|
||||
|
||||
builder: (BuildContext context) {
|
||||
return new AlertDialog(
|
||||
title: new Text('Confirmação'),
|
||||
content: new SingleChildScrollView(
|
||||
child: new ListBody(
|
||||
children: [
|
||||
new Text('Tem certeza que quer remover o cliente ${widget.c
|
||||
.name}?'),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
new TextButton(
|
||||
child: new Text('Sim'),
|
||||
onPressed: () {
|
||||
values[0].text = "CLIENTE_REMOVIDO";
|
||||
values[1].text = "";
|
||||
values[2].text = "";
|
||||
values[3].text = "";
|
||||
_updateClient();
|
||||
|
||||
},
|
||||
),
|
||||
new TextButton(
|
||||
child: new Text('Não'),
|
||||
onPressed: () {
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
364
lib/screens/alterEquipment.dart
Normal file
364
lib/screens/alterEquipment.dart
Normal file
@ -0,0 +1,364 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/screens/equipmentDetail.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:esms_project/widgets/widget_generate.dart';
|
||||
import 'package:esms_project/widgets/widget_input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class alterEquipment extends StatefulWidget {
|
||||
Equipment e;
|
||||
Repair r;
|
||||
alterEquipment(this.e, {this.r});
|
||||
@override
|
||||
_alterEquipmentState createState() => _alterEquipmentState();
|
||||
}
|
||||
|
||||
class _alterEquipmentState extends State<alterEquipment> {
|
||||
Timer d;
|
||||
final values = new List<TextEditingController>.generate(
|
||||
6, (_) => TextEditingController());
|
||||
final _formEq = new GlobalKey<FormState>();
|
||||
final _formRep = new GlobalKey<FormState>();
|
||||
File _image;
|
||||
|
||||
bool _writeRepair = false;
|
||||
List<String> imagens = [];
|
||||
@override
|
||||
void initState() {
|
||||
imagens = widget.e.images;
|
||||
values[0].text = widget.e.name;
|
||||
values[1].text = widget.e.problem;
|
||||
values[2].text = widget.e.observation;
|
||||
values[3].text = DateFormat.yMd().format(widget.e.dateInput);
|
||||
values[4].text = widget.e.dateExit == null
|
||||
? ""
|
||||
: DateFormat.yMd().format(widget.e.dateExit);
|
||||
if (widget.r != null) {
|
||||
values[5].text = widget.r.repair == null ? "" : widget.r.repair;
|
||||
_writeRepair = true;
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if (mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Alterar Informações"),
|
||||
),
|
||||
body: _layout());
|
||||
}
|
||||
|
||||
_layout() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
height: double.infinity,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 20,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.w600),
|
||||
text: "Preencha este formulário com informações do aparelho.",
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Form(
|
||||
key: _formEq,
|
||||
child: Column(
|
||||
children: [
|
||||
InputValidado(
|
||||
"Nome do Aparelho",
|
||||
"Ex.: Radio XYZ",
|
||||
controller: values[0],
|
||||
),
|
||||
InputValidado(
|
||||
"Problema apresentado",
|
||||
"Ex.: Tela quebrada",
|
||||
controller: values[1],
|
||||
),
|
||||
InputTextos(
|
||||
"Observações",
|
||||
"Ex.: Vem com cabos",
|
||||
controller: values[2],
|
||||
),
|
||||
InputData(
|
||||
"Data de Entrada",
|
||||
"Ex. " + DateFormat.yMd().format(DateTime.now()),
|
||||
controller: values[3],
|
||||
),
|
||||
InputDataNoValidate(
|
||||
"Data de Saída",
|
||||
"Ex. " +
|
||||
DateFormat.yMd()
|
||||
.format(DateTime.now().add(Duration(days: 30))),
|
||||
controller: values[4],
|
||||
),
|
||||
],
|
||||
)),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 20,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.w600),
|
||||
text: "Deseja registrar o reparo?",
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Radio(
|
||||
groupValue: _writeRepair,
|
||||
value: true,
|
||||
onChanged: _onChangeRepair,
|
||||
),
|
||||
Text("Sim", style: TextStyle(fontSize: 18)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Radio(
|
||||
groupValue: _writeRepair,
|
||||
value: false,
|
||||
onChanged: _onChangeRepair,
|
||||
),
|
||||
Text("Não", style: TextStyle(fontSize: 18)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
_Repair(),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
Botoes(
|
||||
"Atualizar Aparelho",
|
||||
onPressed: _update,
|
||||
),
|
||||
if (imagens != null && imagens.length <= 10)
|
||||
Botoes(
|
||||
"Tire uma foto!",
|
||||
onPressed: _snapPic,
|
||||
),
|
||||
if (imagens[0].isNotEmpty)
|
||||
Text("Você tirou " + imagens.length.toString() + " fotos."),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _ValidateInputs() {
|
||||
setState(() {});
|
||||
return widget.e != null && _formEq.currentState.validate();
|
||||
}
|
||||
|
||||
bool _ValidateRepair() {
|
||||
setState(() {});
|
||||
return _writeRepair && _formRep.currentState.validate();
|
||||
}
|
||||
|
||||
_Repair() {
|
||||
return _writeRepair
|
||||
? Container(
|
||||
child: Form(
|
||||
key: _formRep,
|
||||
child: Column(
|
||||
children: [
|
||||
InputValidado(
|
||||
"Reparo realizado",
|
||||
"Troca de peça X, Y, Z",
|
||||
controller: values[5],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container();
|
||||
}
|
||||
|
||||
_onChangeRepair(bool value) {
|
||||
setState(() {
|
||||
_writeRepair = value;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _snapPic() async {
|
||||
if (_ValidateInputs()) {
|
||||
Directory dir = await getApplicationDocumentsDirectory();
|
||||
final imagem = await ImagePicker().getImage(source: ImageSource.camera);
|
||||
|
||||
if (imagem != null) {
|
||||
setState(() {
|
||||
_image = File(imagem.path);
|
||||
});
|
||||
final fileName = StringGenerator().getRandomString(10) + ".jpg";
|
||||
final savedImage =
|
||||
await File(_image.path).copy('${dir.path}/Pictures/$fileName');
|
||||
|
||||
if (savedImage != null) {
|
||||
if (imagens[0].isEmpty)
|
||||
imagens[0] = fileName;
|
||||
else
|
||||
imagens.add(fileName);
|
||||
_displaySnackbar("Foto adicionada com sucesso.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_displaySnackbar("Verifique os campos.");
|
||||
}
|
||||
}
|
||||
|
||||
_displaySnackbar(String text) {
|
||||
setState(() {
|
||||
final snackBar =
|
||||
SnackBar(content: Text(text, style: TextStyle(fontSize: 16)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
}
|
||||
|
||||
_update() {
|
||||
setState(() {
|
||||
if(!_writeRepair && widget.r != null) {
|
||||
_deleteRepair(widget.r.id);
|
||||
}
|
||||
else if(_writeRepair || widget.r == null){
|
||||
_updateSt2();
|
||||
}
|
||||
});
|
||||
}
|
||||
_updateSt2()
|
||||
{
|
||||
if (_ValidateInputs()) {
|
||||
int tmp = widget.e.id;
|
||||
int tmp2 = widget.e.client_id;
|
||||
widget.e = new Equipment(
|
||||
tmp2,
|
||||
values[0].text,
|
||||
values[1].text,
|
||||
values[2].text,
|
||||
DateFormat.yMd().parse(values[3].text),
|
||||
);
|
||||
widget.e.id = tmp;
|
||||
if (values[4].text.isNotEmpty)
|
||||
widget.e.EquipmentLeave(DateFormat.yMd().parse(values[4].text));
|
||||
widget.e.images = imagens;
|
||||
widget.e.UpdateDB(tmp);
|
||||
if (_ValidateRepair()) {
|
||||
if (widget.r == null) {
|
||||
widget.r = new Repair(tmp, values[5].text);
|
||||
widget.r.SaveToDB();
|
||||
} else {
|
||||
int tmp3 = widget.r.id;
|
||||
widget.r = new Repair(tmp, values[5].text);
|
||||
widget.r.UpdateDB(tmp3);
|
||||
}
|
||||
}
|
||||
int TryCount = 0;
|
||||
d = Timer(Duration(milliseconds: 200), () {
|
||||
if ((!_writeRepair && widget.e.status == 1) || (widget.r.status == 1 && widget.e.status == 1)) {
|
||||
TryCount = 0;
|
||||
_showcontent(tmp);
|
||||
d.cancel();
|
||||
} else
|
||||
TryCount++;
|
||||
});
|
||||
if (TryCount >= 2) _displaySnackbar("Erro na operação.");
|
||||
}
|
||||
}
|
||||
void _deleteRepair(temp)
|
||||
{
|
||||
setState(() {
|
||||
showDialog(
|
||||
context: context, barrierDismissible: false, // user must tap button!
|
||||
|
||||
builder: (BuildContext context) {
|
||||
return new AlertDialog(
|
||||
title: new Text('Aviso'),
|
||||
content: new SingleChildScrollView(
|
||||
child: new ListBody(
|
||||
children: [
|
||||
new Text('Deseja remover informações sobre reparo?'),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
new TextButton(
|
||||
child: new Text('Sim'),
|
||||
onPressed: () {
|
||||
widget.r.RemoveDB(temp);
|
||||
_updateSt2();
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
},
|
||||
),
|
||||
new TextButton(
|
||||
child: new Text('Não'),
|
||||
onPressed: () {
|
||||
_updateSt2();
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _showcontent(temp) {
|
||||
setState(() {
|
||||
showDialog(
|
||||
context: context, barrierDismissible: false, // user must tap button!
|
||||
|
||||
builder: (BuildContext context) {
|
||||
return new AlertDialog(
|
||||
title: new Text('Aviso'),
|
||||
content: new SingleChildScrollView(
|
||||
child: new ListBody(
|
||||
children: [
|
||||
new Text('Equipamento atualizado.'),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
new TextButton(
|
||||
child: new Text('OK'),
|
||||
onPressed: () {
|
||||
int count = 0;
|
||||
Navigator.of(context).popUntil((_) => count++ >= 2);
|
||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
||||
builder: (context) => EquipmentDetail(temp)));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
200
lib/screens/clientDetail.dart
Normal file
200
lib/screens/clientDetail.dart
Normal file
@ -0,0 +1,200 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/client.dart';
|
||||
import 'package:esms_project/screens/alterClient.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'listEquipmentByClient.dart';
|
||||
|
||||
class ClientDetail extends StatefulWidget {
|
||||
final int id;
|
||||
ClientDetail(this.id);
|
||||
|
||||
@override
|
||||
_ClientDetailState createState() => _ClientDetailState();
|
||||
}
|
||||
|
||||
class _ClientDetailState extends State<ClientDetail> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
Timer stuck;
|
||||
Client cli;
|
||||
|
||||
Future<bool> _loadvars() async {
|
||||
Future<List<Map<String, dynamic>>> tmp = dbh.queryByID("client", widget.id);
|
||||
tmp.then((List<Map<String, dynamic>> value) {
|
||||
cli = Client.fromJson(value[0]);
|
||||
});
|
||||
return true && cli != null;
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
_reload() {
|
||||
stuck = Timer(Duration(seconds: 2), () {
|
||||
loaded = _loadvars();
|
||||
stuck.cancel();
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Detalhes do Cliente"),
|
||||
),
|
||||
body: _layout(),
|
||||
);
|
||||
}
|
||||
|
||||
_layout() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(30),
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done &&
|
||||
cli != null) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Card(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
leading: const Icon(Icons.account_circle),
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: cli.name)),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.phone),
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: "Telefone: ${cli.telephone}",
|
||||
),
|
||||
),
|
||||
onTap: () =>
|
||||
_launchUrl("tel:${cli.telephone}")),
|
||||
ListTile(
|
||||
leading: Icon(Icons.phone_android),
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: "Celular: ${cli.cellular}")),
|
||||
onTap: () => _launchUrl("tel:${cli.cellular}")),
|
||||
ListTile(
|
||||
leading: Icon(Icons.notes),
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text:
|
||||
"Observações: ${cli.observations}")),
|
||||
onTap: () => _modal(
|
||||
cli.observations, "Observações", Icons.notes),
|
||||
),
|
||||
]),
|
||||
),
|
||||
Botoes(
|
||||
"Alterar",
|
||||
onPressed: _update,
|
||||
),
|
||||
Botoes(
|
||||
"Ver Aparelhos",
|
||||
onPressed: () => _list(cli.id),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (snapshot.data == false) {
|
||||
_reload();
|
||||
}
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [CircularProgressIndicator(), Text("Carregando.")],
|
||||
),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
_modal(String value, String type, IconData icon) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) => SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20),
|
||||
semanticLabel: type,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(icon),
|
||||
Text(type),
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.black38),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Colors.black, fontSize: 16),
|
||||
text: value)),
|
||||
Botoes(
|
||||
"Fechar",
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
},
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
_launchUrl(String url) async {
|
||||
await canLaunch(url) ? await launch(url) : print("Uh-oh!");
|
||||
}
|
||||
|
||||
_update() {
|
||||
Navigator.of(context)
|
||||
.push(new MaterialPageRoute(builder: (context) => alterClient(cli)))
|
||||
.whenComplete(_reload);
|
||||
}
|
||||
|
||||
_list(int id) {
|
||||
setState(() {
|
||||
Navigator.of(context)
|
||||
.push(new MaterialPageRoute(builder: (context) => listEquipmentClient(id_client: widget.id,)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
}
|
103
lib/screens/createClient.dart
Normal file
103
lib/screens/createClient.dart
Normal file
@ -0,0 +1,103 @@
|
||||
import 'package:esms_project/client.dart';
|
||||
import 'package:esms_project/screens/listClients.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:esms_project/widgets/widget_input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
class CreateClient extends StatefulWidget {
|
||||
@override
|
||||
_CreateClientState createState() => _CreateClientState();
|
||||
}
|
||||
|
||||
class _CreateClientState extends State<CreateClient> {
|
||||
final values = new List<TextEditingController>.generate(
|
||||
4, (_) => TextEditingController());
|
||||
Client c;
|
||||
final _formCli = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Adicionar Cliente"),
|
||||
),
|
||||
body: _layout());
|
||||
}
|
||||
_layout() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
height: double.infinity,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Form(
|
||||
key: _formCli,
|
||||
child: Column(
|
||||
children: [
|
||||
InputValidado(
|
||||
"Digite o nome do Cliente",
|
||||
"Ex. João da Silva",
|
||||
controller: values[0],
|
||||
),
|
||||
InputTextosPhone(
|
||||
"Digite um telefone",
|
||||
"Ex. (15) 1234-5678",
|
||||
controller: values[1],
|
||||
),
|
||||
InputTextosPhone(
|
||||
"Digite um celular",
|
||||
"Ex. (15) 991234-5678",
|
||||
controller: values[2],
|
||||
),
|
||||
InputTextos(
|
||||
"Observações:",
|
||||
"Ex. Tem (15) 99123-4567 como outro número celular",
|
||||
controller: values[3],
|
||||
),
|
||||
],
|
||||
)),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
Botoes(
|
||||
"Cadastrar cliente",
|
||||
onPressed: _addClient,
|
||||
)
|
||||
]
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
_addClient() {
|
||||
setState(() {
|
||||
if (_formCli.currentState.validate()) {
|
||||
c = new Client(
|
||||
values[0].text, values[1].text, values[2].text, values[3].text);
|
||||
c.SaveToDB();
|
||||
if (c.id != null || c.id != 0) {
|
||||
_displaySnackbar("Cliente cadastrado.");
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (context) => ListClients()));
|
||||
} else {
|
||||
_displaySnackbar("Erro no cadastro.");
|
||||
}
|
||||
} else {
|
||||
_displaySnackbar("Verifique o cadastro!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_displaySnackbar(String text) {
|
||||
setState(() {
|
||||
final snackBar =
|
||||
SnackBar(content: Text(text, style: TextStyle(fontSize: 16)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
}
|
||||
}
|
360
lib/screens/createEquipment.dart
Normal file
360
lib/screens/createEquipment.dart
Normal file
@ -0,0 +1,360 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:esms_project/client.dart';
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/mainScreen.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:esms_project/widgets/widget_generate.dart';
|
||||
import 'package:esms_project/widgets/widget_input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class CreateEquipment extends StatefulWidget {
|
||||
Client c;
|
||||
CreateEquipment({this.c});
|
||||
@override
|
||||
_CreateEquipmentState createState() => _CreateEquipmentState();
|
||||
}
|
||||
|
||||
class _CreateEquipmentState extends State<CreateEquipment> {
|
||||
final values = new List<TextEditingController>.generate(
|
||||
9, (_) => TextEditingController());
|
||||
List<String> imagens = [];
|
||||
List<Map<String, dynamic>> clients;
|
||||
Client c;
|
||||
bool _client = true;
|
||||
bool _justregistered = false;
|
||||
File _image;
|
||||
final _formEq = GlobalKey<FormState>();
|
||||
final _formCli = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
c = widget.c == null? null: widget.c;
|
||||
if(c != null)
|
||||
{
|
||||
_client = true;
|
||||
_justregistered = true;
|
||||
values[3].text = c.name;
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Adicionar Aparelho"),
|
||||
),
|
||||
body: _layout());
|
||||
}
|
||||
|
||||
_layout() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
height: double.infinity,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 20,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.w600),
|
||||
text: "Preencha este formulário com informações do aparelho.",
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Form(
|
||||
key: _formEq,
|
||||
child: Column(
|
||||
children: [
|
||||
InputValidado(
|
||||
"Nome do Aparelho",
|
||||
"Ex.: Radio XYZ",
|
||||
controller: values[0],
|
||||
),
|
||||
InputValidado(
|
||||
"Problema apresentado",
|
||||
"Ex.: Tela quebrada",
|
||||
controller: values[1],
|
||||
),
|
||||
InputTextos(
|
||||
"Observações",
|
||||
"Ex.: Vem com cabos",
|
||||
controller: values[2],
|
||||
),
|
||||
InputData(
|
||||
"Data de Entrada",
|
||||
"Ex. " + DateFormat.yMd().format(DateTime.now()),
|
||||
controller: values[8],
|
||||
)
|
||||
],
|
||||
)),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 20,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.w600),
|
||||
text: "O cliente ja é cadastrado?",
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Radio(
|
||||
groupValue: _client,
|
||||
value: true,
|
||||
onChanged: _onChangeClient,
|
||||
),
|
||||
Text("Sim", style: TextStyle(fontSize: 18)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Radio(
|
||||
groupValue: _client,
|
||||
value: false,
|
||||
onChanged: _onChangeClient,
|
||||
),
|
||||
Text("Não", style: TextStyle(fontSize: 18)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
_clientCheck(),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
if (_justregistered == true)
|
||||
Column(
|
||||
children: [
|
||||
Botoes(
|
||||
"Cadastrar Aparelho",
|
||||
onPressed: _addEquipment,
|
||||
),
|
||||
if (imagens != null && imagens.length <= 10)
|
||||
Botoes(
|
||||
"Tire uma foto!",
|
||||
onPressed: _snapPic,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (imagens != null && imagens.length > 0)
|
||||
Text("Você tirou " + imagens.length.toString() + " fotos.")
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
_onChangeClient(bool value) {
|
||||
setState(() {
|
||||
_client = value;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _GetClient() async {
|
||||
if (values[3] != null && values[3].text.isNotEmpty) {
|
||||
clients = await dbHandler.instance.queryByName("client", values[3].text);
|
||||
List<Map<String,dynamic>> temp = List.empty(growable: true);
|
||||
setState(() {
|
||||
if (clients != null) {
|
||||
for (int i = 0; i < clients.length; i++) {
|
||||
if (clients[i]['name'] != 'CLIENTE_REMOVIDO')
|
||||
temp.add(clients[i]);
|
||||
}
|
||||
clients = temp;
|
||||
}
|
||||
FocusScope.of(context).unfocus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_clientCheck() {
|
||||
return _client
|
||||
? Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InputTextos(
|
||||
"Buscar por nome",
|
||||
"Ex. João da Silva",
|
||||
controller: values[3],
|
||||
)),
|
||||
IconButton(onPressed: _GetClient, icon: Icon(Icons.search))
|
||||
],
|
||||
),
|
||||
if (clients != null)
|
||||
for (int i = 0; i < clients.length; i++)
|
||||
Column(
|
||||
children: [
|
||||
Divider(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Icon(Icons.account_circle_rounded),
|
||||
Text(
|
||||
" Cliente: " + clients[i]['name'].toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w300,
|
||||
),
|
||||
),
|
||||
]),
|
||||
Botoes("Selecionar", onPressed: () => _loadCli(i))
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
Form(
|
||||
key: _formCli,
|
||||
child: Column(
|
||||
children: [
|
||||
InputValidado(
|
||||
"Digite o nome do Cliente",
|
||||
"Ex. João da Silva",
|
||||
controller: values[4],
|
||||
),
|
||||
InputTextosPhone(
|
||||
"Digite um telefone",
|
||||
"Ex. (15) 1234-5678",
|
||||
controller: values[5],
|
||||
),
|
||||
InputTextosPhone(
|
||||
"Digite um celular",
|
||||
"Ex. (15) 991234-5678",
|
||||
controller: values[6],
|
||||
),
|
||||
InputTextos(
|
||||
"Observações:",
|
||||
"Ex. Tem (15) 99123-4567 como outro número celular",
|
||||
controller: values[7],
|
||||
),
|
||||
],
|
||||
)),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
Botoes(
|
||||
"Cadastrar cliente",
|
||||
onPressed: _addClient,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_addClient() {
|
||||
setState(() {
|
||||
if (_formCli.currentState.validate()) {
|
||||
_client = true;
|
||||
c = new Client(
|
||||
values[4].text, values[5].text, values[6].text, values[7].text);
|
||||
c.SaveToDB();
|
||||
if (c.id != null || c.id != 0) {
|
||||
values[3].text = values[4].text;
|
||||
_displaySnackbar("Cliente cadastrado.");
|
||||
_justregistered = true;
|
||||
} else {
|
||||
_displaySnackbar("Erro no cadastro.");
|
||||
}
|
||||
} else {
|
||||
_displaySnackbar("Verifique o cadastro!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool _ValidateInputs() {
|
||||
setState(() {});
|
||||
return _formEq.currentState.validate() && c != null;
|
||||
}
|
||||
|
||||
Future<void> _snapPic() async {
|
||||
if (_ValidateInputs()) {
|
||||
Directory dir = await getApplicationDocumentsDirectory();
|
||||
final imagem = await ImagePicker().getImage(source: ImageSource.camera);
|
||||
|
||||
if (imagem != null) {
|
||||
setState(() {
|
||||
_image = File(imagem.path);
|
||||
});
|
||||
|
||||
final fileName = StringGenerator().getRandomString(10) + ".jpg";
|
||||
final savedImage = await File(imagem.path).copy(
|
||||
'${dir.path}/Pictures/$fileName');
|
||||
if(savedImage != null) {
|
||||
imagens.add(fileName);
|
||||
_displaySnackbar("Foto adicionada com sucesso.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_displaySnackbar(String text) {
|
||||
setState(() {
|
||||
final snackBar =
|
||||
SnackBar(content: Text(text, style: TextStyle(fontSize: 16)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
}
|
||||
|
||||
_addEquipment() {
|
||||
setState(() {
|
||||
if (_formEq.currentState.validate()) {
|
||||
Equipment e = new Equipment(
|
||||
c.id,
|
||||
values[0].text,
|
||||
values[1].text,
|
||||
values[2].text,
|
||||
DateFormat.yMd().parse(values[8].text),
|
||||
);
|
||||
e.AddImageAsRange(imagens);
|
||||
|
||||
if (e.SaveToDB() == 1) {
|
||||
_displaySnackbar("Erro no cadastro!");
|
||||
} else {
|
||||
_displaySnackbar("Cadastrado com sucesso.");
|
||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (context) => mainScreen()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_loadCli(int index) {
|
||||
setState(() {
|
||||
values[3].text = clients[index]['name'].toString();
|
||||
c = Client.fromJson(clients[index]);
|
||||
clients = null;
|
||||
_justregistered = true;
|
||||
});
|
||||
}
|
||||
}
|
288
lib/screens/equipmentDetail.dart
Normal file
288
lib/screens/equipmentDetail.dart
Normal file
@ -0,0 +1,288 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:esms_project/widgets/widget_caroussel.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'alterEquipment.dart';
|
||||
|
||||
class EquipmentDetail extends StatefulWidget {
|
||||
final int id;
|
||||
EquipmentDetail(this.id);
|
||||
|
||||
@override
|
||||
_EquipmentDetailState createState() => _EquipmentDetailState();
|
||||
}
|
||||
|
||||
class _EquipmentDetailState extends State<EquipmentDetail> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
Timer stuck, d;
|
||||
bool openProblem = false;
|
||||
bool openObservation = false;
|
||||
Equipment eq;
|
||||
Repair r;
|
||||
Future<bool> _loadvars() async {
|
||||
dbh
|
||||
.queryByID("equipment", widget.id)
|
||||
.then((List<Map<String, dynamic>> value) {
|
||||
eq = Equipment.fromJson(value[0]);
|
||||
});
|
||||
dbh
|
||||
.queryByID("v_repair", widget.id)
|
||||
.then((List<Map<String, dynamic>> value) {
|
||||
r = Repair.fromView(value[0]);
|
||||
});
|
||||
|
||||
return true && eq != null;
|
||||
}
|
||||
|
||||
_reload() {
|
||||
stuck = Timer(Duration(seconds: 2), () {
|
||||
loaded = _loadvars();
|
||||
stuck.cancel();
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if (mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Detalhes do Aparelho"),
|
||||
),
|
||||
body: _layout(),
|
||||
);
|
||||
}
|
||||
|
||||
_layout() {
|
||||
return Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done &&
|
||||
eq != null) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Card(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: "N°" + eq.id.toString())),
|
||||
),
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: eq.name)),
|
||||
Divider(color: Colors.black38),
|
||||
Column(children: [
|
||||
if (eq.images.length > 0)
|
||||
eq.images[0].isNotEmpty
|
||||
? SizedBox(
|
||||
height: 270,
|
||||
child: Caroussel(eq.images))
|
||||
: SizedBox(
|
||||
height: 170,
|
||||
child: Center(
|
||||
child: RichText(
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 30.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black26,
|
||||
fontSize: 30,
|
||||
fontWeight:
|
||||
FontWeight.w300,
|
||||
fontStyle:
|
||||
FontStyle.italic),
|
||||
text: "Sem Imagem")),
|
||||
)),
|
||||
]),
|
||||
Divider(color: Colors.black38),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.warning),
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: "Problema : " + '${eq.problem}',
|
||||
),
|
||||
),
|
||||
onTap: () => _modal('${eq.problem}', "Problema",
|
||||
Icons.warning_amber_outlined),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.info),
|
||||
title: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 16),
|
||||
text: "Observações : " +
|
||||
'${eq.observation}')),
|
||||
onTap: () => _modal('${eq.observation}',
|
||||
"Observações", Icons.info_outline),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.calendar_today),
|
||||
title: Text("Data de Entrada: " +
|
||||
'${DateFormat.yMMMd().format(eq.dateInput)}'),
|
||||
),
|
||||
_Eval(),
|
||||
Divider(color: Colors.black38),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Botoes(
|
||||
"Alterar",
|
||||
onPressed: _update,
|
||||
),
|
||||
Botoes(
|
||||
"Remover",
|
||||
onPressed: _remove,
|
||||
)
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.transparent),
|
||||
]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (snapshot.data == false) {
|
||||
_reload();
|
||||
}
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
_Eval() {
|
||||
return eq.dateExit != null
|
||||
? ListTile(
|
||||
leading: Icon(Icons.calendar_today_outlined),
|
||||
title: Text("Data de Entrega: " +
|
||||
'${DateFormat.yMMMd().format(eq.dateExit)}'))
|
||||
: Container(width: 0, height: 0);
|
||||
}
|
||||
|
||||
_update() {
|
||||
setState(() {
|
||||
Navigator.of(context)
|
||||
.push(new MaterialPageRoute(
|
||||
builder: (context) => alterEquipment(eq, r: r)))
|
||||
.whenComplete(_reload);
|
||||
});
|
||||
}
|
||||
|
||||
_remove() {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) => SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20),
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(Icons.warning_amber_outlined),
|
||||
Text("Confirmação de Ação")
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.black38),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Colors.black, fontSize: 16),
|
||||
text: "Deseja realmente remover ${eq.name}?")
|
||||
),
|
||||
Divider(color: Colors.transparent),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Botoes("Sim", onPressed: (){
|
||||
eq.RemoveDB(eq.id);
|
||||
if(r != null)
|
||||
r.RemoveDB(r.id);
|
||||
d = Timer(Duration(milliseconds: 200), ()
|
||||
{
|
||||
if ((r != null && r.status == 1 && eq.status == 1) ||
|
||||
(r == null && eq.status == 1)) {
|
||||
d.cancel();
|
||||
int count = 0;
|
||||
Navigator.of(context).popUntil((_) => count++ >= 2);
|
||||
}
|
||||
});
|
||||
/**/
|
||||
},),
|
||||
Botoes("Não", onPressed: (){
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
},)
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
_modal(String value, String type, IconData icon) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) => SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20),
|
||||
semanticLabel: type,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(icon),
|
||||
Text(type),
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.black38),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(fontSize: 12.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Colors.black, fontSize: 16),
|
||||
text: value)),
|
||||
Botoes(
|
||||
"Fechar",
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
||||
},
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
210
lib/screens/listClients.dart
Normal file
210
lib/screens/listClients.dart
Normal file
@ -0,0 +1,210 @@
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/screens/clientDetail.dart';
|
||||
import 'package:esms_project/screens/createClient.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
|
||||
class ListClients extends StatefulWidget {
|
||||
@override
|
||||
_ListClientsState createState() => _ListClientsState();
|
||||
}
|
||||
|
||||
class _ListClientsState extends State<ListClients> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
List<Map<String, dynamic>> cliList = List.empty(growable: true);
|
||||
|
||||
Future<bool> _loadvars() async {
|
||||
cliList = List.empty(growable: true);
|
||||
dbh.queryOrdered("client", "ASC", "name").then((value) {
|
||||
List<Map<String,dynamic>> tmp = value;
|
||||
for(int i = 0; i < tmp.length; i++)
|
||||
{
|
||||
if(tmp[i]['name'] != "CLIENTE_REMOVIDO")
|
||||
{
|
||||
cliList.add(tmp[i]);
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
return true && cliList != null;
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Listagem de Clientes"),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.add_box_outlined),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
Navigator.of(context)
|
||||
.push(new MaterialPageRoute(
|
||||
builder: (context) => CreateClient()))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return Container(
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (cliList != null && cliList.length != 0) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: cliList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
height: 90,
|
||||
color: Colors.black12,
|
||||
child: InkWell(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 18.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Colors.black, fontSize: 18.0),
|
||||
text: "Cliente: " +
|
||||
'${cliList[index]['name']}')),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 18.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Colors.black, fontSize: 18.0),
|
||||
text: "Celular: " +
|
||||
'${cliList[index]['cellular']}'))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
onTap: () =>
|
||||
onPressWithArg(context, cliList[index]['id']),
|
||||
));
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider());
|
||||
} else {
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "Estou vazio!"),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text:
|
||||
"Cadastre um cliente clicando no botão "),
|
||||
),
|
||||
Icon(
|
||||
Icons.add_box_outlined,
|
||||
color: Colors.black26,
|
||||
),
|
||||
]),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "\nOu tente recarregar a tela."),
|
||||
),
|
||||
Botoes(
|
||||
"Recarregar",
|
||||
onPressed: () => _update(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_update(BuildContext context) {
|
||||
setState(() {
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (context) => ListClients()));
|
||||
});
|
||||
}
|
||||
|
||||
onPressWithArg(context, int id) {
|
||||
setState(() {
|
||||
Navigator.of(context)
|
||||
.push(new MaterialPageRoute(builder: (context) => ClientDetail(id)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
}
|
236
lib/screens/listEquipment.dart
Normal file
236
lib/screens/listEquipment.dart
Normal file
@ -0,0 +1,236 @@
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/screens/createEquipment.dart';
|
||||
import 'package:esms_project/screens/equipmentDetail.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class listEquipment extends StatefulWidget {
|
||||
@override
|
||||
_listEquipmentState createState() => _listEquipmentState();
|
||||
}
|
||||
|
||||
class _listEquipmentState extends State<listEquipment> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
List<Map<String, dynamic>> eqList;
|
||||
|
||||
Future<bool> _loadvars() async {
|
||||
dbh.queryAllEquipment().then((value) {
|
||||
eqList = value;
|
||||
setState(() {
|
||||
return true && eqList != null;
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Aparelhos para Conserto"),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
onPressed: () => _addItem(context),
|
||||
icon: Icon(Icons.add_box_outlined))
|
||||
],
|
||||
),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return Container(
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (eqList != null && eqList.length != 0) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: eqList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
height: 90,
|
||||
color: Colors.black12,
|
||||
child: InkWell(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text:
|
||||
"Aparelho: "+'${eqList[index]['equipment']}'))),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Cliente: " +
|
||||
'${eqList[index]['name']}'))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Data: " +
|
||||
'${DateFormat.yMd().format(DateTime.tryParse(eqList[index]['dateInput']))}'))),
|
||||
],
|
||||
),
|
||||
]),
|
||||
),
|
||||
onTap: () => onPressWithArg(
|
||||
context,
|
||||
eqList[index]['id'],
|
||||
)));
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider());
|
||||
} else {
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "Estou vazio!"),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text:
|
||||
"Cadastre um aparelho clicando no botão "),
|
||||
),
|
||||
Icon(
|
||||
Icons.add_box_outlined,
|
||||
color: Colors.black26,
|
||||
),
|
||||
]),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "\nOu tente recarregar a tela."),
|
||||
),
|
||||
Botoes(
|
||||
"Recarregar",
|
||||
onPressed: () => _update(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_update(ctx) {
|
||||
setState(() {
|
||||
Navigator.pushReplacement(
|
||||
ctx, MaterialPageRoute(builder: (context) => listEquipment()));
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
void load(int arg) async {
|
||||
Equipment t = new Equipment(0, "", "", "", DateTime.now());
|
||||
t = await t.LoadFromDB(arg);
|
||||
}
|
||||
|
||||
void onPressWithArg(ctx, int id) {
|
||||
setState(() {
|
||||
Navigator.of(ctx)
|
||||
.push(
|
||||
new MaterialPageRoute(builder: (context) => EquipmentDetail(id)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
|
||||
_addItem(ctx) {
|
||||
setState(() {
|
||||
Navigator.of(ctx)
|
||||
.push(new MaterialPageRoute(builder: (context) => CreateEquipment()))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
}
|
283
lib/screens/listEquipmentByClient.dart
Normal file
283
lib/screens/listEquipmentByClient.dart
Normal file
@ -0,0 +1,283 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:esms_project/client.dart';
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/screens/createEquipment.dart';
|
||||
import 'package:esms_project/screens/equipmentDetail.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class listEquipmentClient extends StatefulWidget {
|
||||
int id_client;
|
||||
String clientName;
|
||||
listEquipmentClient({this.id_client,this.clientName});
|
||||
@override
|
||||
_listEquipmentClientState createState() => _listEquipmentClientState();
|
||||
}
|
||||
|
||||
class _listEquipmentClientState extends State<listEquipmentClient> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
List<Map<String, dynamic>> eqList;
|
||||
Client c;
|
||||
int count = 0;
|
||||
Timer stuck;
|
||||
Future<bool> _loadvars() async {
|
||||
if(widget.id_client!=null) {
|
||||
dbh.queryByID("client", widget.id_client).then((value) {
|
||||
c = Client.fromJson(value[0]);
|
||||
});
|
||||
widget.clientName = null;
|
||||
dbh.queryEquipmentClient(widget.id_client).then((value) {
|
||||
eqList = value;
|
||||
});
|
||||
}
|
||||
if(widget.clientName != null)
|
||||
{
|
||||
widget.id_client = null;
|
||||
dbh.queryByName("v_equipment", widget.clientName).then((value) {
|
||||
eqList = value;
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
return true && eqList != null;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
_reload() {
|
||||
if(count < 2)
|
||||
stuck = Timer(Duration(seconds: 1), () {
|
||||
if(eqList == null)
|
||||
loaded = _loadvars();
|
||||
stuck.cancel();
|
||||
count++;
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Resultados da Pesquisa"),
|
||||
actions: <Widget>[
|
||||
if(widget.id_client != null)
|
||||
IconButton(
|
||||
onPressed: () => _addItem(context),
|
||||
icon: Icon(Icons.add_box_outlined))
|
||||
],
|
||||
),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return Container(
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (eqList != null && eqList.length > 0) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: eqList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
height: 90,
|
||||
color: Colors.black12,
|
||||
child: InkWell(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text:
|
||||
'${eqList[index]['equipment']}'))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 18.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text:
|
||||
'${eqList[index]['problem']}'))),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Data: " +
|
||||
'${DateFormat.yMd().format(DateTime.tryParse(eqList[index]['dateInput']))}'))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Cliente: "+eqList[index]['name'])
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
]),
|
||||
),
|
||||
onTap: () => onPressWithArg(
|
||||
context,
|
||||
eqList[index]['id'],
|
||||
)));
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider());
|
||||
}
|
||||
if (snapshot.data == null) {
|
||||
_reload();
|
||||
}
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "Estou vazio!"),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text:
|
||||
"Cadastre um aparelho clicando no botão "),
|
||||
),
|
||||
Icon(
|
||||
Icons.add_box_outlined,
|
||||
color: Colors.black26,
|
||||
),
|
||||
]),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "\nOu tente recarregar a tela."),
|
||||
),
|
||||
Botoes(
|
||||
"Recarregar",
|
||||
onPressed: () => _update(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_update(ctx) {
|
||||
setState(() {
|
||||
Navigator.pushReplacement(
|
||||
ctx,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => listEquipmentClient(id_client: widget.id_client, clientName: widget.clientName,)));
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
void load(int arg) async {
|
||||
Equipment t = new Equipment(0, "", "", "", DateTime.now());
|
||||
t = await t.LoadFromDB(arg);
|
||||
}
|
||||
|
||||
void onPressWithArg(ctx, int id) {
|
||||
setState(() {
|
||||
Navigator.of(ctx)
|
||||
.push(
|
||||
new MaterialPageRoute(builder: (context) => EquipmentDetail(id)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
|
||||
_addItem(ctx) {
|
||||
setState(() {
|
||||
Navigator.of(ctx)
|
||||
.push(new MaterialPageRoute(builder: (context) => CreateEquipment(c: c)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
}
|
236
lib/screens/listEquipmentByID.dart
Normal file
236
lib/screens/listEquipmentByID.dart
Normal file
@ -0,0 +1,236 @@
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/screens/equipmentDetail.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class listEquipmentID extends StatefulWidget {
|
||||
final int id;
|
||||
|
||||
listEquipmentID(this.id);
|
||||
@override
|
||||
_listEquipmentIDState createState() => _listEquipmentIDState();
|
||||
}
|
||||
|
||||
class _listEquipmentIDState extends State<listEquipmentID> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
List<Map<String, dynamic>> eqList;
|
||||
|
||||
Future<bool> _loadvars() async {
|
||||
dbh.queryByID("v_equipment", widget.id).then((value) {
|
||||
eqList = value;
|
||||
setState(() {
|
||||
return true && eqList != null;
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Resultados da Pesquisa"),
|
||||
),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return Container(
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (eqList != null && eqList.length != 0) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: eqList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
height: 90,
|
||||
color: Colors.black12,
|
||||
child: InkWell(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text: "Aparelho: " +
|
||||
'${eqList[index]['equipment']}'))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Cliente: " +
|
||||
'${eqList[index]['name']}'))),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Entrada: " +
|
||||
'${DateFormat.yMd().format(DateTime.tryParse(eqList[index]['dateInput']))}'))),
|
||||
if (eqList != null && DateTime.tryParse(eqList[index]['dateExit']) != null)
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Saída: " +
|
||||
'${DateFormat.yMd().format(DateTime.tryParse(eqList[index]['dateExit']))}')))
|
||||
],
|
||||
),
|
||||
]),
|
||||
),
|
||||
onTap: () => onPressWithArg(
|
||||
context,
|
||||
eqList[index]['id'],
|
||||
)));
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider());
|
||||
} else {
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "Estou vazio!"),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text:
|
||||
"Cadastre um aparelho clicando no botão "),
|
||||
),
|
||||
Icon(
|
||||
Icons.add_box_outlined,
|
||||
color: Colors.black26,
|
||||
),
|
||||
]),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "\nOu tente recarregar a tela."),
|
||||
),
|
||||
Botoes(
|
||||
"Recarregar",
|
||||
onPressed: () => _update(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_update(ctx) {
|
||||
setState(() {
|
||||
Navigator.pushReplacement(ctx,
|
||||
MaterialPageRoute(builder: (context) => listEquipmentID(widget.id)));
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
void load(int arg) async {
|
||||
Equipment t = new Equipment(0, "", "", "", DateTime.now());
|
||||
t = await t.LoadFromDB(arg);
|
||||
}
|
||||
|
||||
void onPressWithArg(ctx, int id) {
|
||||
setState(() {
|
||||
Navigator.of(ctx)
|
||||
.push(
|
||||
new MaterialPageRoute(builder: (context) => EquipmentDetail(id)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
}
|
228
lib/screens/listEquipmentDelivered.dart
Normal file
228
lib/screens/listEquipmentDelivered.dart
Normal file
@ -0,0 +1,228 @@
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/screens/equipmentDetail.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:esms_project/electronic.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class listEquipmentDelivered extends StatefulWidget {
|
||||
@override
|
||||
_listEquipmentDeliveredState createState() => _listEquipmentDeliveredState();
|
||||
}
|
||||
|
||||
class _listEquipmentDeliveredState extends State<listEquipmentDelivered> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
List<Map<String, dynamic>> eqList;
|
||||
|
||||
Future<bool> _loadvars() async {
|
||||
dbh.queryAllEquipmentDelivered().then((value) {
|
||||
eqList = value;
|
||||
setState(() {
|
||||
return true && eqList != null;
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(fn) {
|
||||
if(mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Aparelhos Entregues"),
|
||||
),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return Container(
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (eqList != null && eqList.length != 0) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: eqList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
height: 90,
|
||||
color: Colors.black12,
|
||||
child: InkWell(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text:
|
||||
"Aparelho: "+'${eqList[index]['equipment']}'))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Cliente: " +
|
||||
'${eqList[index]['name']}'))),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Entrada: " +
|
||||
'${DateFormat.yMd().format(DateTime.tryParse(eqList[index]['dateInput']))}'))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle:
|
||||
StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black),
|
||||
text: "Entrega: " +
|
||||
'${DateFormat.yMd().format(DateTime.tryParse(eqList[index]['dateExit']))}')))
|
||||
],
|
||||
),
|
||||
]),
|
||||
),
|
||||
onTap: () => onPressWithArg(
|
||||
context,
|
||||
eqList[index]['id'],
|
||||
)));
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider());
|
||||
} else {
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "Estou vazio!"),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text:
|
||||
"Nenhum aparelho entregue até o momento."),
|
||||
),
|
||||
]),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "\nTente recarregar a tela."),
|
||||
),
|
||||
Botoes(
|
||||
"Recarregar",
|
||||
onPressed: () => _update(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_update(ctx) {
|
||||
setState(() {
|
||||
Navigator.pushReplacement(
|
||||
ctx, MaterialPageRoute(builder: (context) => listEquipmentDelivered()));
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
void load(int arg) async {
|
||||
Equipment t = new Equipment(0, "", "", "", DateTime.now());
|
||||
t = await t.LoadFromDB(arg);
|
||||
}
|
||||
|
||||
void onPressWithArg(ctx, int id) {
|
||||
setState(() {
|
||||
Navigator.of(ctx)
|
||||
.push(
|
||||
new MaterialPageRoute(builder: (context) => EquipmentDetail(id)))
|
||||
.whenComplete(_loadvars);
|
||||
});
|
||||
}
|
||||
}
|
260
lib/screens/listRepairs.dart
Normal file
260
lib/screens/listRepairs.dart
Normal file
@ -0,0 +1,260 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:esms_project/dbhandler.dart';
|
||||
import 'package:esms_project/screens/equipmentDetail.dart';
|
||||
import 'package:esms_project/widgets/widget_button.dart';
|
||||
import 'package:esms_project/widgets/widget_input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../electronic.dart';
|
||||
|
||||
class ListRepairs extends StatefulWidget {
|
||||
@override
|
||||
_ListRepairsState createState() => _ListRepairsState();
|
||||
}
|
||||
|
||||
class _ListRepairsState extends State<ListRepairs> {
|
||||
final dbHandler dbh = dbHandler.instance;
|
||||
Future<bool> loaded;
|
||||
|
||||
List<Map<String, dynamic>> repList;
|
||||
Future<bool> _loadvars() async {
|
||||
dbh.queryOrdered("v_repair", "ASC", "name").then((value) {
|
||||
repList = value;
|
||||
setState(() {
|
||||
return true && repList != null;
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
@override
|
||||
void setState(fn) {
|
||||
if (mounted) {
|
||||
super.setState(fn);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loaded = _loadvars();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Exemplares de Consertos"),
|
||||
actions: [
|
||||
IconButton(onPressed: (){
|
||||
showSearch(context: context, delegate: CustomSearch(type: 0, loadList: repList));
|
||||
}, icon: Icon(Icons.search))
|
||||
],
|
||||
),
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return Container(
|
||||
child: FutureBuilder<bool>(
|
||||
future: loaded,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
else if (repList != null && repList.length != 0) {
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: repList.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
height: 90,
|
||||
color: Colors.black12,
|
||||
child: InkWell(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 18.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text: "Aparelho: " +
|
||||
'${repList[index]['name']}')),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
strutStyle: StrutStyle(fontSize: 18.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18.0),
|
||||
text: "Reparo: " +
|
||||
'${repList[index]['repair']}'))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
onTap: () => onPressWithArg(
|
||||
repList[index]['repair'],repList[index]['id'],repList[index]['repair_id']),
|
||||
));
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider());
|
||||
} else {
|
||||
return Container(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "Nenhum reparo cadastrado."),
|
||||
),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic),
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontStyle: FontStyle.italic,
|
||||
color: Colors.black26),
|
||||
text: "\nTente recarregar a tela."),
|
||||
),
|
||||
Botoes(
|
||||
"Recarregar",
|
||||
onPressed: () => _update(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_update(BuildContext context) {
|
||||
setState(() {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
Navigator.of(context).push(new MaterialPageRoute(builder: (context)=> ListRepairs()));
|
||||
});
|
||||
}
|
||||
|
||||
onPressWithArg(String rep, int id, int repid) {
|
||||
setState(() {
|
||||
_modalInput(rep, id, repid);
|
||||
});
|
||||
}
|
||||
|
||||
_modalInput(String repair, int eq, int rep) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) => SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20),
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("Detalhes do Reparo"),
|
||||
IconButton(
|
||||
iconSize: 20,
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pop('dialog');
|
||||
},
|
||||
icon: Icon(Icons.close))
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.black38),
|
||||
RichText(
|
||||
strutStyle: StrutStyle(fontSize: 16.0),
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Colors.black, fontSize: 20.0, fontWeight: FontWeight.w300),
|
||||
text:repair)),
|
||||
Divider(color: Colors.transparent),
|
||||
Botoes(
|
||||
"Ver Aparelho",
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(new MaterialPageRoute(builder: (context) => EquipmentDetail(eq)))
|
||||
.whenComplete(_loadvars);
|
||||
},
|
||||
),
|
||||
Botoes(
|
||||
"Remover Reparo",
|
||||
onPressed: () {
|
||||
_confirmDelete(rep);
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
_confirmDelete(int id)
|
||||
{
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) => SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20),
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("Deseja remover o reparo?"),
|
||||
IconButton(
|
||||
iconSize: 20,
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pop('dialog');
|
||||
},
|
||||
icon: Icon(Icons.close))
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.black38),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Botoes("Sim", onPressed: (){
|
||||
Repair r = new Repair(0,"temp");
|
||||
r.RemoveDB(id);
|
||||
setState(() {
|
||||
_update(context);
|
||||
});
|
||||
},), Botoes("Não", onPressed: (){
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pop('dialog');
|
||||
})
|
||||
],)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user