You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.9 KiB
Dart
127 lines
3.9 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:car_provider_app/api/client/profile_api_client.dart';
|
|
import 'package:car_provider_app/classes/app_state.dart';
|
|
import 'package:car_provider_app/classes/utils.dart';
|
|
import 'package:car_provider_app/models/profile/document.dart';
|
|
import 'package:car_provider_app/utils/utils.dart';
|
|
import 'package:car_provider_app/widgets/show_fill_button.dart';
|
|
import 'package:car_provider_app/widgets/txt_field.dart';
|
|
import 'package:file_picker/file_picker.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:car_provider_app/extensions/int_extensions.dart';
|
|
|
|
class DefineLicensePage extends StatefulWidget {
|
|
@override
|
|
State<DefineLicensePage> createState() => _DefineLicensePageState();
|
|
}
|
|
|
|
class _DefineLicensePageState extends State<DefineLicensePage> {
|
|
Document? document;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
getDocuments();
|
|
}
|
|
|
|
getDocuments() async {
|
|
document = await ProfileApiClent().getServiceProviderDocument(AppState().getUser.data!.userInfo!.providerId ?? 0);
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("Define Licenses"),
|
|
),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: showWidget(),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: ShowFillButton(
|
|
title: "Update",
|
|
width: double.infinity,
|
|
onPressed: () {
|
|
Utils.showLoading(context);
|
|
ProfileApiClent().serviceProviderDocumentsUpdate(document!.data).then((value) {
|
|
Utils.hideLoading(context);
|
|
if (value.messageStatus == 1) {
|
|
Utils.showToast("Documents uploaded successfully");
|
|
} else {
|
|
Utils.showToast(value.message ?? "");
|
|
}
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget showWidget() {
|
|
if (document != null) {
|
|
return document!.data!.length == 0
|
|
? Text("Something went wrong")
|
|
: ListView.separated(
|
|
itemBuilder: (context, index) {
|
|
return Row(
|
|
children: [
|
|
Flexible(
|
|
child: TxtField(
|
|
hint: "Select Attachment",
|
|
value: document?.data![index].documentUrl ?? "",
|
|
isNeedClickAll: true,
|
|
maxLines: 2,
|
|
),
|
|
),
|
|
IconButton(
|
|
onPressed: () {
|
|
selectFile(index);
|
|
},
|
|
icon: Icon(Icons.insert_link_rounded),
|
|
)
|
|
],
|
|
);
|
|
},
|
|
separatorBuilder: (context, index) {
|
|
return 12.height;
|
|
},
|
|
padding: EdgeInsets.all(12),
|
|
itemCount: document!.data!.length,
|
|
);
|
|
} else {
|
|
return Center(
|
|
child: CircularProgressIndicator(),
|
|
);
|
|
}
|
|
}
|
|
|
|
selectFile(int index) async {
|
|
FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.custom, allowedExtensions: ['png', 'pdf', 'jpeg']);
|
|
|
|
if (result != null) {
|
|
File file = File(result.files.single.path ?? "");
|
|
|
|
document!.data![index].document = convertFileToBase64(file);
|
|
document!.data![index].fileExt = checkFileExt(file.path);
|
|
setState(() {
|
|
document!.data![index].documentUrl = result.files.single.path ?? "";
|
|
});
|
|
} else {
|
|
// User canceled the picker
|
|
}
|
|
}
|
|
}
|