342 lines
9.9 KiB
Dart
342 lines
9.9 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mobile_portal_23/classes/common_classes.dart';
|
|
import 'package:mobile_portal_23/models/employee_model.dart';
|
|
import 'package:mobile_portal_23/models/reportListModel.dart';
|
|
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
String appDomain = "iotechnic.eu";
|
|
|
|
class ReportCreate extends StatefulWidget {
|
|
const ReportCreate({Key? key}) : super(key: key);
|
|
static const routeName = '/reportNew';
|
|
@override
|
|
State<ReportCreate> createState() => _ReportCreateState();
|
|
}
|
|
late EmployeePageArguments employeePageArguments;
|
|
late ReportArguments reportArguments;
|
|
|
|
Future<List<EmployeeLs>> fetchData(String userApiKey) async {
|
|
var url = "http://$appDomain/apiemployeelist/$userApiKey";
|
|
http.Response response = await http.get(Uri.parse(url));
|
|
var resp = jsonDecode(response.body);
|
|
if (kDebugMode) {
|
|
print(resp.toString());
|
|
}
|
|
|
|
return resp.map<EmployeeLs>((m) => EmployeeLs.fromJson(m)).toList();
|
|
}
|
|
|
|
|
|
class _ReportCreateState extends State<ReportCreate> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
late List<String> favoriteWorks = [];
|
|
bool _isError = false;
|
|
bool _isData = false;
|
|
final bool _showFaworites = false;
|
|
late List<WorkListModel> workList = [];
|
|
// late EmployeeArguments empArgs;
|
|
|
|
Future<void> getSharedPrefs() async {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// userApiKey = prefs.getString("apiKey");
|
|
favoriteWorks = prefs.getStringList("favoriteWorks") ?? [];
|
|
}
|
|
|
|
Future fetchdata() async {
|
|
var res = await http.get(
|
|
|
|
// "http://iotechnic.eu/apiGetAllReport/X8B0PQS-2KYMCV3-G5WD74N-8G0CRAH");
|
|
Uri.parse("http://$appDomain/apiGetAllWork/${employeePageArguments.apiKey!}"));
|
|
//"http://192.168.0.144/apiGetDailyReport/X8B0PQS-2KYMCV3-G5WD74N-8G0CRAH");
|
|
if (res.statusCode == 200) {
|
|
var obj = json.decode(res.body);
|
|
return obj;
|
|
}
|
|
}
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final args = ModalRoute.of(context)!.settings.arguments as Map;
|
|
|
|
employeePageArguments = args['userArgs'];
|
|
});
|
|
getSharedPrefs().then((value) {
|
|
fetchdata().then((data) {
|
|
if (data != null) {
|
|
for (var item in data) {
|
|
// reportList.add(ModelReportList.fromJson(item));
|
|
workList.add(WorkListModel.fromJson(item));
|
|
}
|
|
_isData = true;
|
|
setState(() {
|
|
debugPrint('Fetch ok.');
|
|
});
|
|
} else {
|
|
_isError = true;
|
|
}
|
|
//employeeList = data;
|
|
/* empArgs = (ModalRoute.of(context)?.settings.arguments ??
|
|
<String, dynamic>{}) as EmployeeArguments;*/
|
|
});
|
|
});
|
|
super.initState();
|
|
}
|
|
int currentStep = 0;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<String> emp = [];
|
|
|
|
/* final arguments =
|
|
ModalRoute.of(context)!.settings.arguments as ReportArguments;*/
|
|
final args = ModalRoute
|
|
.of(context)!
|
|
.settings
|
|
.arguments as Map;
|
|
|
|
// employeePageArguments = args['userArgs'];
|
|
//reportArguments = args['dataArgs'];
|
|
return Scaffold(
|
|
//resizeToAvoidBottomInset: false,
|
|
appBar: AppBar(
|
|
title: const Text("Új jelentés"),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.search),
|
|
onPressed: () {},
|
|
),
|
|
|
|
],
|
|
actionsIconTheme: const IconThemeData(
|
|
size: 32,
|
|
),
|
|
),
|
|
//drawer: Drawer(),
|
|
|
|
body: page(context),
|
|
|
|
bottomNavigationBar: BottomAppBar(
|
|
color: Colors.cyan,
|
|
child: Container(
|
|
height: 50.0,
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
//visible: _enableSave,
|
|
|
|
|
|
}
|
|
|
|
Widget page(BuildContext context) {
|
|
|
|
return Container(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Stepper(
|
|
type: StepperType.horizontal,
|
|
currentStep: currentStep,
|
|
onStepCancel: () => currentStep == 0
|
|
? null
|
|
: setState(() {
|
|
currentStep -= 1;
|
|
}),
|
|
onStepContinue: () {
|
|
bool isLastStep = (currentStep == getSteps().length - 1);
|
|
if (isLastStep) {
|
|
//Do something with this information
|
|
} else {
|
|
setState(() {
|
|
currentStep += 1;
|
|
});
|
|
}
|
|
},
|
|
onStepTapped: (step) => setState(() {
|
|
currentStep = step;
|
|
}),
|
|
steps: getSteps(),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Step> getSteps() {
|
|
return <Step>[
|
|
Step(
|
|
state: currentStep > 0 ? StepState.complete : StepState.indexed,
|
|
isActive: currentStep >= 0,
|
|
title: const Text("Ibrányi"),
|
|
content: selectWork(context)
|
|
),
|
|
Step(
|
|
state: currentStep > 1 ? StepState.complete : StepState.indexed,
|
|
isActive: currentStep >= 1,
|
|
title: const Text("Address"),
|
|
content: const Column(
|
|
children: [
|
|
Text("Ibrányi"),
|
|
],
|
|
),
|
|
),
|
|
Step(
|
|
state: currentStep > 2 ? StepState.complete : StepState.indexed,
|
|
isActive: currentStep >= 2,
|
|
title: const Text("Misc"),
|
|
content: const Column(
|
|
children: [
|
|
Text("Ibrányi"),
|
|
],
|
|
),
|
|
),
|
|
];
|
|
}
|
|
|
|
|
|
Container selectWork(BuildContext context) {
|
|
return _isData == false
|
|
? _isError
|
|
? Container(
|
|
child: const AlertDialog(
|
|
title: Text('Hálózati Hiba!'),
|
|
content: Icon(Icons.error_outline),
|
|
elevation: 24,
|
|
backgroundColor: Colors.red),
|
|
)
|
|
: Container(
|
|
child: SizedBox(
|
|
height: MediaQuery
|
|
.of(context)
|
|
.size
|
|
.height / 1.3,
|
|
width: MediaQuery
|
|
.of(context)
|
|
.size
|
|
.width,
|
|
child: const Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
))
|
|
: gridList(context);
|
|
}
|
|
|
|
Container gridList(BuildContext context) {
|
|
//List<ModelReportList> _reportList = [];
|
|
List<WorkListModel> workList = [];
|
|
if (_showFaworites) {
|
|
workList = workList
|
|
.where((element) => favoriteWorks.contains(element.sId))
|
|
.toList();
|
|
} else {
|
|
workList = workList;
|
|
}
|
|
return Container(
|
|
color: const Color(0xffECF0F1),
|
|
child: ListView.builder(
|
|
itemCount: workList.length, // The length Of the array
|
|
|
|
padding: const EdgeInsets.all(5),
|
|
shrinkWrap: true,
|
|
|
|
itemBuilder: (context, index) => Container(
|
|
child: reportCard(context, workList[index]),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
Card reportCard(BuildContext context, WorkListModel item) {
|
|
int workHour = 0;
|
|
bool workOpened = false;
|
|
bool isFaworite = favoriteWorks.contains(item.sId);
|
|
if (item.state!.contains("Opened")) workOpened = true;
|
|
/* item.dailyReport.forEach((element) {
|
|
workHour += element.employeeList.length;
|
|
});*/
|
|
return Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(
|
|
children: [
|
|
ListTile(
|
|
tileColor: workOpened ? Colors.indigo : Colors.grey,
|
|
trailing: IconButton(
|
|
onPressed: () {
|
|
if (isFaworite) {
|
|
favoriteWorks.remove(item.sId);
|
|
} else {
|
|
String? id = item.sId;
|
|
favoriteWorks.add(id!);
|
|
}
|
|
// _saveFavoriteWorks(favoriteWorks);
|
|
},
|
|
icon: isFaworite
|
|
? Icon(
|
|
Icons.star,
|
|
color: favoriteWorks.contains(item.sId)
|
|
? Colors.yellow
|
|
: null,
|
|
)
|
|
: const Icon(Icons.star_border)),
|
|
onTap: workOpened
|
|
? () {
|
|
ReportArguments reportArgs = ReportArguments(
|
|
List.empty(),
|
|
//userApiKey!,
|
|
item.title!,
|
|
item.sId!,
|
|
item.state == "Opened" ? true : false,
|
|
//empArgs.isForeman!
|
|
);
|
|
|
|
/** Navigator.pushNamed(context, reportNew.routeName,
|
|
arguments: {
|
|
'userArgs': employeePageArguments,
|
|
'dataArgs': reportArgs
|
|
});*/
|
|
}
|
|
: null,
|
|
title: Text(
|
|
item.title!,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
/*subtitle: Text(
|
|
item.body!,
|
|
style: TextStyle(color: Colors.yellow.withOpacity(0.6)),
|
|
),*/
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: IntrinsicHeight(
|
|
child: Column(children: [
|
|
Text(
|
|
item.body!.replaceAll("\n", " "),
|
|
style: TextStyle(color: Colors.green.withOpacity(0.6)),
|
|
),
|
|
const Divider(
|
|
thickness: 1.0,
|
|
),
|
|
Row(children: [
|
|
|
|
Text(
|
|
'KL${item.workNumber!}',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black.withOpacity(0.6)),
|
|
),
|
|
const VerticalDivider(color: Colors.grey, thickness: 1, width: 30),
|
|
Text(
|
|
'PO: ${item.poNumber!}',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black.withOpacity(0.6)),
|
|
),
|
|
]),
|
|
]))),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
|