build_app
This commit is contained in:
parent
8a3162f243
commit
b484671d03
@ -69,6 +69,9 @@ public class BuilderService {
|
||||
executeDump(true);
|
||||
|
||||
// ADD OTHER SERVICE
|
||||
addCustomMenu( "Forma","Forma", "Transcations");
|
||||
|
||||
|
||||
|
||||
System.out.println("dashboard and menu inserted...");
|
||||
|
||||
|
||||
@ -0,0 +1,155 @@
|
||||
package com.realnet.basic1.Controllers;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.data.domain.*;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import com.realnet.basic1.Entity.Forma;
|
||||
import com.realnet.basic1.Services.FormaService ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/Forma")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class FormaController {
|
||||
@Autowired
|
||||
private FormaService Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/Forma")
|
||||
public Forma Savedata(@RequestBody Forma data) {
|
||||
Forma save = Service.Savedata(data) ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
@PutMapping("/Forma/{id}")
|
||||
public Forma update(@RequestBody Forma data,@PathVariable Integer id ) {
|
||||
Forma update = Service.update(data,id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
// get all with pagination
|
||||
@GetMapping("/Forma/getall/page")
|
||||
public Page<Forma> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Forma> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
@GetMapping("/Forma")
|
||||
public List<Forma> getdetails() {
|
||||
List<Forma> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Forma")
|
||||
public List<Forma> getallwioutsec() {
|
||||
List<Forma> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
@GetMapping("/Forma/{id}")
|
||||
public Forma getdetailsbyId(@PathVariable Integer id ) {
|
||||
Forma get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
@DeleteMapping("/Forma/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,155 @@
|
||||
package com.realnet.basic1.Controllers;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.data.domain.*;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import com.realnet.basic1.Entity.Forma;
|
||||
import com.realnet.basic1.Services.FormaService ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/token/Forma")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class tokenFree_FormaController {
|
||||
@Autowired
|
||||
private FormaService Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/Forma")
|
||||
public Forma Savedata(@RequestBody Forma data) {
|
||||
Forma save = Service.Savedata(data) ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
@PutMapping("/Forma/{id}")
|
||||
public Forma update(@RequestBody Forma data,@PathVariable Integer id ) {
|
||||
Forma update = Service.update(data,id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
// get all with pagination
|
||||
@GetMapping("/Forma/getall/page")
|
||||
public Page<Forma> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Forma> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
@GetMapping("/Forma")
|
||||
public List<Forma> getdetails() {
|
||||
List<Forma> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Forma")
|
||||
public List<Forma> getallwioutsec() {
|
||||
List<Forma> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
@GetMapping("/Forma/{id}")
|
||||
public Forma getdetailsbyId(@PathVariable Integer id ) {
|
||||
Forma get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
@DeleteMapping("/Forma/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
package com.realnet.basic1.Entity;
|
||||
import lombok.*;
|
||||
import com.realnet.WhoColumn.Entity.Extension;
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Forma extends Extension {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String radio_field;
|
||||
|
||||
|
||||
|
||||
|
||||
private Boolean a;
|
||||
|
||||
|
||||
|
||||
private Boolean b;
|
||||
|
||||
|
||||
|
||||
private String fileupload_fieldname;
|
||||
private String fileupload_fieldpath ;
|
||||
|
||||
private String imageupload_fieldname;
|
||||
private String imageupload_fieldpath ;
|
||||
|
||||
private String video_fieldname;
|
||||
private String video_fieldpath ;
|
||||
|
||||
private String audio_fieldname;
|
||||
private String audio_fieldpath ;
|
||||
|
||||
private String currency;
|
||||
|
||||
private String qrcode_field;
|
||||
|
||||
private String barcode_field;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.realnet.basic1.Repository;
|
||||
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import com.realnet.basic1.Entity.Forma;
|
||||
|
||||
@Repository
|
||||
public interface FormaRepository extends JpaRepository<Forma, Integer> {
|
||||
|
||||
@Query(value = "select * from forma where created_by=?1", nativeQuery = true)
|
||||
List<Forma> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from forma where created_by=?1", nativeQuery = true)
|
||||
Page<Forma> findAll( Long creayedBy,Pageable page);
|
||||
}
|
||||
@ -0,0 +1,173 @@
|
||||
package com.realnet.basic1.Services;
|
||||
import com.realnet.basic1.Repository.FormaRepository;
|
||||
import com.realnet.basic1.Entity.Forma
|
||||
;import java.util.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.realnet.SequenceGenerator.Service.SequenceService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import com.realnet.realm.Entity.Realm;
|
||||
import com.realnet.realm.Services.RealmService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.*;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class FormaService {
|
||||
@Autowired
|
||||
private FormaRepository Repository;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
@Autowired
|
||||
private RealmService realmService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Forma Savedata(Forma data) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
data.setCreatedBy(getUser().getUserId());
|
||||
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||
Forma save = Repository.save(data);
|
||||
return save;
|
||||
}
|
||||
|
||||
|
||||
// get all with pagination
|
||||
public Page<Forma> getAllWithPagination(Pageable page) {
|
||||
return Repository.findAll( getUser().getUserId(),page);
|
||||
}
|
||||
public List<Forma> getdetails() {
|
||||
List<Realm> realm = realmService.findByUserId(getUser().getUserId());
|
||||
List<Forma> all = Repository.findAll(getUser().getUserId());
|
||||
|
||||
return all ; }
|
||||
|
||||
|
||||
public Forma getdetailsbyId(Integer id) {
|
||||
return Repository.findById(id).get();
|
||||
}
|
||||
|
||||
|
||||
public void delete_by_id(Integer id) {
|
||||
Repository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
public Forma update(Forma data,Integer id) {
|
||||
Forma old = Repository.findById(id).get();
|
||||
old.setName(data.getName());
|
||||
|
||||
old.setRadio_field(data.getRadio_field());
|
||||
|
||||
|
||||
|
||||
old.setA(data.getA());
|
||||
|
||||
|
||||
|
||||
old.setB(data.getB());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
old.setCurrency(data.getCurrency());
|
||||
|
||||
old.setQrcode_field(data.getQrcode_field());
|
||||
|
||||
old.setBarcode_field(data.getBarcode_field());
|
||||
|
||||
final Forma test = Repository.save(old);
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
return test;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public AppUser getUser() {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
return user;
|
||||
|
||||
}}
|
||||
@ -0,0 +1,112 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import '../../../../resources/api_constants.dart';
|
||||
import '../../../../data/network/base_network_service.dart';
|
||||
import '../../../../data/network/network_api_service.dart';
|
||||
|
||||
class FormaApiService {
|
||||
final String baseUrl = ApiConstants.baseUrl;
|
||||
|
||||
final BaseNetworkService _helper = NetworkApiService();
|
||||
|
||||
|
||||
|
||||
Future<List<Map<String, dynamic>>> getEntities() async {
|
||||
|
||||
try {
|
||||
final response = await _helper.getGetApiResponse('$baseUrl/Forma/Forma');
|
||||
final entities = (response as List).cast<Map<String, dynamic>>();
|
||||
return entities;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get all entities: $e');
|
||||
}
|
||||
}
|
||||
Future<List<Map<String, dynamic>>> getAllWithPagination(
|
||||
int page, int size) async {
|
||||
try {
|
||||
final response =
|
||||
await _helper.getGetApiResponse('$baseUrl/Forma/Forma/getall/page?page=$page&size=$size');
|
||||
final entities =
|
||||
(response['content'] as List).cast<Map<String, dynamic>>();
|
||||
return entities;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get all without pagination: $e');
|
||||
}
|
||||
}
|
||||
Future<Map<String, dynamic>> createEntity(
|
||||
Map<String, dynamic> entity) async {
|
||||
try {
|
||||
print("in post api$entity");
|
||||
final response =
|
||||
await _helper.getPostApiResponse('$baseUrl/Forma/Forma', entity);
|
||||
|
||||
print(entity);
|
||||
|
||||
// Assuming the response is a Map<String, dynamic>
|
||||
Map<String, dynamic> responseData = response;
|
||||
|
||||
return responseData;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to create entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future<void> updateEntity( int entityId, Map<String, dynamic> entity) async {
|
||||
try {
|
||||
await _helper.getPutApiResponse('$baseUrl/Forma/Forma/$entityId',
|
||||
entity); print(entity);
|
||||
|
||||
} catch (e) {
|
||||
throw Exception('Failed to update entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteEntity( int entityId) async {
|
||||
try {
|
||||
await _helper.getDeleteApiResponse('$baseUrl/Forma/Forma/$entityId');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to delete entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../Forma_viewModel/Forma_view_model_screen.dart';
|
||||
import 'Forma_fields.dart';import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
|
||||
import '../../../../utils/image_constant.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../../../widgets/custom_button.dart';
|
||||
import '../../../../widgets/custom_text_form_field.dart';
|
||||
import '../../../../widgets/custom_dropdown_field.dart';
|
||||
import 'dart:math';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import '../../../../Reuseable/reusable_date_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_time_picker_field.dart'
|
||||
;import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import 'dart:io';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import '../../../../Reuseable/reusable_dropdown_field.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FormaCreateEntityScreen extends StatefulWidget {
|
||||
const FormaCreateEntityScreen({super.key});
|
||||
|
||||
@override
|
||||
_FormaCreateEntityScreenState createState() => _FormaCreateEntityScreenState();
|
||||
}
|
||||
|
||||
class _FormaCreateEntityScreenState extends State<FormaCreateEntityScreen> {
|
||||
|
||||
final Map<String, dynamic> formData = {};
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<FormaViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityCreateScreen(
|
||||
fields: FormaFields.getFields(context),
|
||||
onSubmit: (data) => _handleSubmit(data),
|
||||
title: 'Forma',
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit(Map<String, dynamic> formData) async {
|
||||
final provider =
|
||||
Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
final success = await provider.createEntity(formData);
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../BuilderField/shared/ui/entity_details.dart';
|
||||
import '../Forma_viewModel/Forma_view_model_screen.dart';
|
||||
import 'Forma_update_entity_screen.dart';
|
||||
|
||||
class FormaDetailsScreen extends StatefulWidget {
|
||||
final Map<String, dynamic> entity;
|
||||
|
||||
const FormaDetailsScreen({
|
||||
super.key,
|
||||
required this.entity,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FormaDetailsScreen> createState() => _FormaDetailsScreenState();
|
||||
}
|
||||
|
||||
class _FormaDetailsScreenState extends State<FormaDetailsScreen> {
|
||||
void _navigateToUpdateScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => FormaViewModelScreen(),
|
||||
child: FormaUpdateEntityScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
// Refresh the details screen with updated data
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
void _showDeleteDialog(Map<String, dynamic> entity) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Deletion'),
|
||||
content: const Text('Are you sure you want to delete this Forma?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final vm =
|
||||
Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
final success = await vm.deleteEntity(entity['id']);
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context); // Go back to list
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<FormaViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityDetails(
|
||||
entity: widget.entity,
|
||||
onEdit: (entity) => _navigateToUpdateScreen(entity),
|
||||
onDelete: (entity) => _showDeleteDialog(entity),
|
||||
title: 'Forma',
|
||||
displayFields: [
|
||||
{'key': 'name', 'label': 'Name', 'type': 'text'},
|
||||
|
||||
{'key': 'radio_field', 'label': 'Radio Field', 'type': 'radio'},
|
||||
|
||||
{'key': 'checkbox_field', 'label': 'checkbox Field', 'type': 'checkbox'},
|
||||
|
||||
{'key': 'fileupload_field', 'label': 'Fileupload Field', 'type': 'file'},
|
||||
|
||||
{'key': 'imageupload_field', 'label': 'Imageupload Field', 'type': 'image'},
|
||||
|
||||
{'key': 'video_field', 'label': 'video Field', 'type': 'video'},
|
||||
|
||||
{'key': 'audio_field', 'label': 'audio Field', 'type': 'audio'},
|
||||
|
||||
{'key': 'currency', 'label': 'Currency', 'type': 'currency'},
|
||||
|
||||
{'key': 'qrcode_field', 'label': 'QRCode Field', 'type': 'qr_code'},
|
||||
|
||||
{'key': 'barcode_field', 'label': 'BarCode Field', 'type': 'bar_code'},
|
||||
|
||||
],
|
||||
isLoading: viewModel.isLoading,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,163 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:base_project/BuilderField/shared/ui/entity_list.dart';
|
||||
import 'Forma_create_entity_screen.dart';
|
||||
import 'Forma_update_entity_screen.dart';
|
||||
import '../Forma_viewModel/Forma_view_model_screen.dart';
|
||||
import 'Forma_details_screen.dart';import 'package:flutter/services.dart';
|
||||
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../widgets/custom_icon_button.dart';
|
||||
import '../../../../utils/image_constant.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../../../theme/app_decoration.dart';
|
||||
import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
class Forma_entity_list_screen extends StatefulWidget {
|
||||
static const String routeName = '/entity-list';
|
||||
|
||||
@override
|
||||
_Forma_entity_list_screenState createState() => _Forma_entity_list_screenState();
|
||||
}
|
||||
|
||||
class _Forma_entity_list_screenState extends State<Forma_entity_list_screen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
void _loadData() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
final vm = Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
vm.getAllWithPagination(refresh: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToCreateScreen() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => FormaViewModelScreen(),
|
||||
child: const FormaCreateEntityScreen(),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
final vm = Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
vm.refreshData();
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToUpdateScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => FormaViewModelScreen(),
|
||||
child: FormaUpdateEntityScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
final vm = Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
vm.refreshData();
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToDetailsScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => FormaViewModelScreen(),
|
||||
child: FormaDetailsScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteDialog(Map<String, dynamic> entity) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Deletion'),
|
||||
content: const Text('Are you sure you want to delete this Forma?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final vm =
|
||||
Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
await vm.deleteEntity(entity['id']);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<FormaViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityList(
|
||||
entities: viewModel.filteredList,
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
hasMoreData: viewModel.hasMoreData,
|
||||
searchQuery: viewModel.searchQuery,
|
||||
onSearchChanged: (query) => viewModel.searchforma(query),
|
||||
onEdit: (entity) => _navigateToUpdateScreen(entity),
|
||||
onDelete: (entity) => _showDeleteDialog(entity),
|
||||
onTap: (entity) => _navigateToDetailsScreen(entity),
|
||||
onRefresh: () => viewModel.refreshData(),
|
||||
onLoadMore: () => viewModel.getAllWithPagination(),
|
||||
title: 'Forma',
|
||||
onAddNew: _navigateToCreateScreen,
|
||||
displayFields: [
|
||||
{'key': 'name', 'label': 'Name', 'type': 'text'},
|
||||
|
||||
{'key': 'radio_field', 'label': 'Radio Field', 'type': 'radio'},
|
||||
|
||||
{'key': 'checkbox_field', 'label': 'checkbox Field', 'type': 'checkbox'},
|
||||
|
||||
{'key': 'fileupload_field', 'label': 'Fileupload Field', 'type': 'file'},
|
||||
|
||||
{'key': 'imageupload_field', 'label': 'Imageupload Field', 'type': 'image'},
|
||||
|
||||
{'key': 'video_field', 'label': 'video Field', 'type': 'video'},
|
||||
|
||||
{'key': 'audio_field', 'label': 'audio Field', 'type': 'audio'},
|
||||
|
||||
{'key': 'currency', 'label': 'Currency', 'type': 'currency'},
|
||||
|
||||
{'key': 'qrcode_field', 'label': 'QRCode Field', 'type': 'qr_code'},
|
||||
|
||||
{'key': 'barcode_field', 'label': 'BarCode Field', 'type': 'bar_code'},
|
||||
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,143 @@
|
||||
import 'package:base_project/BuilderField/shared/fields/number_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/password_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/phone_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/custom_text_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/base_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/date_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/datetime_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/email_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/url_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/custom_text_field.dart' as shared_text;
|
||||
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/calculated_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/one_to_many_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/value_list_picker_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/captcha_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/switch_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/url_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/audio_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/checkbox_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/file_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/image_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/radio_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/video_upload_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/autocomplete_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/autocomplete_multiselect_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/data_grid_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dynamic_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dynamic_multiselect_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/static_multiselect_field.dart';import '../Forma_viewModel/Forma_view_model_screen.dart';/// Field definitions for Forma entity
|
||||
/// This defines the structure and validation for Forma forms
|
||||
class FormaFields {
|
||||
/// Get field definitions for Forma entity
|
||||
static List<BaseField> getFields(BuildContext context) {
|
||||
final viewModel =
|
||||
Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
return [
|
||||
// Basic Information
|
||||
CustomTextField(
|
||||
fieldKey: 'name',
|
||||
label: 'Name',
|
||||
hint: 'Enter Name',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
RadioField(
|
||||
fieldKey: 'radio_field',
|
||||
label: 'Radio Field',
|
||||
options: const [
|
||||
|
||||
|
||||
'f',
|
||||
|
||||
|
||||
|
||||
|
||||
'm',
|
||||
|
||||
|
||||
|
||||
|
||||
],
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
|
||||
|
||||
CheckboxField(
|
||||
fieldKey: 'a',
|
||||
label: 'A',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
|
||||
|
||||
CheckboxField(
|
||||
fieldKey: 'b',
|
||||
label: 'B',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
|
||||
|
||||
FileUploadField(
|
||||
fieldKey: 'fileupload_field',
|
||||
label: 'Fileupload Field',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
ImageUploadField(
|
||||
fieldKey: 'imageupload_field',
|
||||
label: 'Imageupload Field',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
VideoUploadField(
|
||||
fieldKey: 'video_field',
|
||||
label: 'video Field',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
AudioUploadField(
|
||||
fieldKey: 'audio_field',
|
||||
label: 'audio Field',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
CustomTextField(
|
||||
fieldKey: 'currency',
|
||||
label: 'Currency',
|
||||
hint: 'Enter Currency',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
CustomTextField(
|
||||
fieldKey: 'qrcode_field',
|
||||
label: 'QRCode Field',
|
||||
hint: 'Enter QRCode Field',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
CustomTextField(
|
||||
fieldKey: 'barcode_field',
|
||||
label: 'BarCode Field',
|
||||
hint: 'Enter BarCode Field',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../Forma_viewModel/Forma_view_model_screen.dart';
|
||||
import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
|
||||
import 'Forma_fields.dart';import '../../../../utils/image_constant.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import '../../../../widgets/custom_button.dart';
|
||||
import '../../../../widgets/custom_text_form_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'dart:math';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_time_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_dropdown_field.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
class FormaUpdateEntityScreen extends StatefulWidget {
|
||||
final Map<String, dynamic> entity;
|
||||
|
||||
|
||||
FormaUpdateEntityScreen({required this.entity});
|
||||
|
||||
@override
|
||||
_FormaUpdateEntityScreenState createState() => _FormaUpdateEntityScreenState();
|
||||
}
|
||||
|
||||
class _FormaUpdateEntityScreenState extends State<FormaUpdateEntityScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<FormaViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
// Start with all fields, then remove upload fields (generic filter by keys)
|
||||
final Set<String> hiddenKeys = {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'fileupload_field',
|
||||
|
||||
'imageupload_field',
|
||||
|
||||
'video_field',
|
||||
|
||||
'audio_field',
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
final fields = FormaFields.getFields(context)
|
||||
.where((f) => !hiddenKeys.contains(f.fieldKey))
|
||||
.toList(); return EntityUpdateScreen(
|
||||
fields: fields,
|
||||
initialData: widget.entity,
|
||||
onSubmit: (data) => _handleSubmit(data),
|
||||
title: 'Forma',
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit(Map<String, dynamic> formData) async {
|
||||
final provider =
|
||||
Provider.of<FormaViewModelScreen>(context, listen: false);
|
||||
final success = await provider.updateEntity(widget.entity['id'], formData);
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,128 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../data/network/base_network_service.dart';
|
||||
import '../../../../data/network/network_api_service.dart';
|
||||
import '../../../../resources/api_constants.dart';
|
||||
import 'package:base_project/data/response/api_response.dart';
|
||||
|
||||
class FormaRepoScreen {
|
||||
|
||||
final String baseUrl = ApiConstants.baseUrl;
|
||||
final BaseNetworkService _helper = NetworkApiService();
|
||||
final String _endpointPath = '/Forma/Forma';
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getEntities() async {
|
||||
try {
|
||||
final response =
|
||||
await _helper.getGetApiResponse('$baseUrl$_endpointPath');
|
||||
return ApiResponse.success(response as List<Map<String, dynamic>>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to get all entities: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getAllWithPagination(
|
||||
int page, int size) async {
|
||||
try {
|
||||
final response = await _helper.getGetApiResponse(
|
||||
'$baseUrl$_endpointPath/getall/page?page=$page&size=$size');
|
||||
|
||||
if (response is Map<String, dynamic> && response['content'] is List) {
|
||||
final List<Map<String, dynamic>> entities =
|
||||
(response['content'] as List).cast<Map<String, dynamic>>().toList();
|
||||
return ApiResponse.success(entities);
|
||||
} else {
|
||||
return ApiResponse.error('Invalid response format');
|
||||
}
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to get all without pagination: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> createEntity(
|
||||
Map<String, dynamic> entity) async {
|
||||
try {
|
||||
print("in post api$entity");
|
||||
final response =
|
||||
await _helper.getPostApiResponse('$baseUrl$_endpointPath', entity);
|
||||
return ApiResponse.success(response as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to create entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> updateEntity(
|
||||
int entityId, Map<String, dynamic> entity) async {
|
||||
try {
|
||||
final response = await _helper.getPutApiResponse(
|
||||
'$baseUrl$_endpointPath/$entityId', entity);
|
||||
return ApiResponse.success(response as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to update entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<void>> deleteEntity(int entityId) async {
|
||||
try {
|
||||
await _helper.getDeleteApiResponse('$baseUrl$_endpointPath/$entityId');
|
||||
return ApiResponse.success(null);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to delete entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future<dynamic> fileupload_fieldUpload(
|
||||
String ref, String refTableNmae, FormData entity) async {
|
||||
try {
|
||||
String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
|
||||
final response = await _helper.getPostApiResponse(apiUrl, entity);
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to Upload File: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> imageupload_fieldUpload(
|
||||
String ref, String refTableNmae, FormData entity) async {
|
||||
try {
|
||||
String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
|
||||
final response = await _helper.getPostApiResponse(apiUrl, entity);
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to Upload Imageupload Field: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> video_fieldUpload(
|
||||
String ref, String refTableNmae, FormData entity) async {
|
||||
try {
|
||||
String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
|
||||
final response = await _helper.getPostApiResponse(apiUrl, entity);
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to Upload File: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> audio_fieldUpload(
|
||||
String ref, String refTableNmae, FormData entity) async {
|
||||
try {
|
||||
String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
|
||||
final response = await _helper.getPostApiResponse(apiUrl, entity);
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to Upload File: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,781 @@
|
||||
import 'package:base_project/data/response/status.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import '../../../../BuilderField/shared/utils/entity_field_store.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../Forma_Repo/Forma_repo_screen.dart';
|
||||
|
||||
class FormaViewModelScreen extends ChangeNotifier{
|
||||
final FormaRepoScreen repo = FormaRepoScreen();
|
||||
|
||||
|
||||
// State variables
|
||||
List<Map<String, dynamic>> _formaList = [];
|
||||
List<Map<String, dynamic>> _filteredList = [];
|
||||
bool _isLoading = false;
|
||||
String _errorMessage = '';
|
||||
int _currentPage = 0;
|
||||
int _pageSize = 10;
|
||||
bool _hasMoreData = true;
|
||||
String _searchQuery = '';
|
||||
|
||||
// Getters
|
||||
List<Map<String, dynamic>> get formaList => _formaList;
|
||||
List<Map<String, dynamic>> get filteredList => _filteredList;
|
||||
bool get isLoading => _isLoading;
|
||||
String get errorMessage => _errorMessage;
|
||||
bool get hasMoreData => _hasMoreData;
|
||||
String get searchQuery => _searchQuery;
|
||||
|
||||
// Set loading state
|
||||
void _setLoading(bool loading) {
|
||||
_isLoading = loading;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Set error message
|
||||
void _setError(String error) {
|
||||
_errorMessage = error;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Clear error
|
||||
void clearError() {
|
||||
_errorMessage = '';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Get forma list
|
||||
Future<void> getEntities() async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.getEntities();
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
_formaList = response.data ?? [];
|
||||
_filteredList = List.from(_formaList);
|
||||
_currentPage = 0;
|
||||
_hasMoreData = true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to fetch forma list');
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to fetch forma list: $e');
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Get forma list with pagination
|
||||
Future<void> getAllWithPagination({bool refresh = false}) async {
|
||||
if (refresh) {
|
||||
_currentPage = 0;
|
||||
_formaList.clear();
|
||||
_filteredList.clear();
|
||||
_hasMoreData = true;
|
||||
}
|
||||
|
||||
if (!_hasMoreData || _isLoading) return;
|
||||
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.getAllWithPagination(_currentPage, _pageSize);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
final newItems = response.data ?? [];
|
||||
|
||||
if (refresh) {
|
||||
_formaList = newItems;
|
||||
} else {
|
||||
_formaList.addAll(newItems);
|
||||
}
|
||||
|
||||
_filteredList = List.from(_formaList);
|
||||
_currentPage++;
|
||||
|
||||
// Check if we have more data
|
||||
_hasMoreData = newItems.length == _pageSize;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to fetch Forma list');
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to fetch forma list: $e');
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Variable to store image files
|
||||
List<Map<String, dynamic>> _fileupload_fieldFiles = [];
|
||||
|
||||
// Variable to store image files
|
||||
List<Map<String, dynamic>> _imageupload_fieldimageFiles = [];
|
||||
|
||||
// Variable to store image files
|
||||
List<Map<String, dynamic>> _video_fieldvideoFiles = [];
|
||||
|
||||
// Variable to store image files
|
||||
List<Map<String, dynamic>> _audio_fieldaudioFiles = [];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Create Forma
|
||||
Future<bool> createEntity(Map<String, dynamic> entity) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Always source image selections from EntityFieldStore for simplicity
|
||||
final List<UploadItem> storefilefileupload_field = EntityFieldStore.instance
|
||||
.get<List<UploadItem>>('fileupload_field') ??
|
||||
<UploadItem>[];
|
||||
|
||||
_fileupload_fieldFiles = storefilefileupload_field
|
||||
.map((u) => {'path': u.fileName, 'bytes': u.bytes})
|
||||
.toList();
|
||||
|
||||
|
||||
entity.remove('fileupload_field');
|
||||
|
||||
|
||||
// Always source image selections from EntityFieldStore for simplicity
|
||||
final List<UploadItem> storeImgsimageupload_field = EntityFieldStore.instance
|
||||
.get<List<UploadItem>>('imageupload_field') ??
|
||||
<UploadItem>[];
|
||||
|
||||
_imageupload_fieldimageFiles = storeImgsimageupload_field
|
||||
.map((u) => {'path': u.fileName, 'bytes': u.bytes})
|
||||
.toList();
|
||||
|
||||
|
||||
entity.remove('imageupload_field');
|
||||
|
||||
|
||||
// Always source image selections from EntityFieldStore for simplicity
|
||||
final List<UploadItem> storevideovideo_field = EntityFieldStore.instance
|
||||
.get<List<UploadItem>>('video_field') ??
|
||||
<UploadItem>[];
|
||||
|
||||
_video_fieldvideoFiles = storevideovideo_field
|
||||
.map((u) => {'path': u.fileName, 'bytes': u.bytes})
|
||||
.toList();
|
||||
|
||||
|
||||
entity.remove('video_field');
|
||||
|
||||
|
||||
// Always source image selections from EntityFieldStore for simplicity
|
||||
final List<UploadItem> storeaudioaudio_field = EntityFieldStore.instance
|
||||
.get<List<UploadItem>>('audio_field') ??
|
||||
<UploadItem>[];
|
||||
|
||||
_audio_fieldaudioFiles = storeaudioaudio_field
|
||||
.map((u) => {'path': u.fileName, 'bytes': u.bytes})
|
||||
.toList();
|
||||
|
||||
|
||||
entity.remove('audio_field');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final response = await repo.createEntity(entity);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
// Get the response ID for image upload
|
||||
|
||||
final responseId = response.data!['id'].toString();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Upload File if available
|
||||
if (_fileupload_fieldFiles.isNotEmpty) {
|
||||
await _uploadfileupload_field(responseId, _fileupload_fieldFiles);
|
||||
_fileupload_fieldFiles.clear(); // Clear after upload
|
||||
}
|
||||
|
||||
// Upload images if available
|
||||
if (_imageupload_fieldimageFiles.isNotEmpty) {
|
||||
await _uploadimageupload_field(responseId, _imageupload_fieldimageFiles);
|
||||
_imageupload_fieldimageFiles.clear(); // Clear after upload
|
||||
}
|
||||
|
||||
// Upload Video if available
|
||||
if (_video_fieldvideoFiles.isNotEmpty) {
|
||||
await _uploadvideo_field(responseId, _video_fieldvideoFiles);
|
||||
_video_fieldvideoFiles.clear(); // Clear after upload
|
||||
}
|
||||
|
||||
// Upload Audio if available
|
||||
if (_audio_fieldaudioFiles.isNotEmpty) {
|
||||
await _uploadaudio_field(responseId, _audio_fieldaudioFiles);
|
||||
_audio_fieldaudioFiles.clear(); // Clear after upload
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'forma created successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Refresh the list
|
||||
await getEntities();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EntityFieldStore.instance.remove('fileupload_field');
|
||||
|
||||
|
||||
EntityFieldStore.instance.remove('imageupload_field');
|
||||
|
||||
|
||||
EntityFieldStore.instance.remove('video_field');
|
||||
|
||||
|
||||
EntityFieldStore.instance.remove('audio_field');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to create Forma');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to create Forma',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to create forma: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to create Forma: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Update forma
|
||||
Future<bool> updateEntity(int id, Map<String, dynamic> entity) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.updateEntity(id, entity);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Forma updated successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Update the item in the list
|
||||
final index = _formaList.indexWhere((item) => item['id'] == id);
|
||||
if (index != -1) {
|
||||
_formaList[index] = response.data!;
|
||||
_filteredList = List.from(_formaList);
|
||||
notifyListeners();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to update Forma');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to update Forma',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to update forma: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to update Forma: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete forma
|
||||
Future<bool> deleteEntity(int id) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.deleteEntity(id);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Forma deleted successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Remove the item from the list
|
||||
_formaList.removeWhere((item) => item['id'] == id);
|
||||
_filteredList = List.from(_formaList);
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to delete Forma');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to delete Forma',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to delete forma: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to delete Forma: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Search forma
|
||||
void searchforma(String query) {
|
||||
_searchQuery = query;
|
||||
|
||||
if (query.isEmpty) {
|
||||
_filteredList = List.from(_formaList);
|
||||
} else {
|
||||
_filteredList = _formaList.where((item) {
|
||||
return
|
||||
|
||||
|
||||
(item['name']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['radio_field']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['video_field']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['audio_field']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['currency']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['qrcode_field']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['barcode_field']?.toString().toLowerCase().contains(query.toLowerCase()) ??false)
|
||||
|
||||
|
||||
;
|
||||
}).toList();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Clear search
|
||||
void clearSearch() {
|
||||
_searchQuery = '';
|
||||
_filteredList = List.from(_formaList);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Refresh data
|
||||
Future<void> refreshData() async {
|
||||
await getAllWithPagination(refresh: true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Helper method to upload multiple image files
|
||||
Future<void> _uploadfileupload_field(
|
||||
String responseId, List<dynamic> Files) async {
|
||||
try {
|
||||
for (var File in Files) {
|
||||
if (File is Map<String, dynamic> &&
|
||||
File.containsKey('path')) {
|
||||
String filePath = File['path'];
|
||||
Uint8List fileBytes = File['bytes'];
|
||||
|
||||
// Upload each image file
|
||||
await uploadfileupload_field(
|
||||
responseId, 'Forma', filePath, fileBytes);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
print('Error uploading files: $error');
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload images", toastType: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the uploadfileupload_fieldimage function
|
||||
Future<void> uploadfileupload_field(String ref, String refTableNmae,
|
||||
String selectedFilePath, Uint8List imageTimageBytes) async {
|
||||
try {
|
||||
|
||||
final Uint8List fileBytes = imageTimageBytes!;
|
||||
final mimeType = fileupload_fieldlookupMimeType(selectedFilePath);
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
'file': MultipartFile.fromBytes(
|
||||
fileBytes,
|
||||
filename: selectedFilePath
|
||||
.split('/')
|
||||
.last, // Get the file name from the path
|
||||
contentType: MediaType.parse(mimeType!),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
await repo.fileupload_fieldUpload(ref, refTableNmae, formData).then((value) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: "File uploaded successfully",
|
||||
toastType: ToastType.success);
|
||||
}).onError(
|
||||
(error, stackTrace) {
|
||||
print("error--$error");
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload file", toastType: ToastType.error);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
print('Error occurred during form submission: $error');
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the lookupMimeType function if needed
|
||||
String fileupload_fieldlookupMimeType(String filePath) {
|
||||
final ext = filePath.split('.').last;
|
||||
switch (ext) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'pdf':
|
||||
return 'application/pdf';
|
||||
// Add more cases for other file types as needed
|
||||
default:
|
||||
return 'application/octet-stream'; // Default MIME type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Helper method to upload multiple image files
|
||||
Future<void> _uploadimageupload_field(
|
||||
String responseId, List<dynamic> imageFiles) async {
|
||||
try {
|
||||
for (var imageFile in imageFiles) {
|
||||
if (imageFile is Map<String, dynamic> &&
|
||||
imageFile.containsKey('path')) {
|
||||
String filePath = imageFile['path'];
|
||||
Uint8List fileBytes = imageFile['bytes'];
|
||||
|
||||
// Upload each image file
|
||||
await uploadimageupload_field(
|
||||
responseId, 'Forma', filePath, fileBytes);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
print('Error uploading image files: $error');
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload images", toastType: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the uploadimageupload_fieldimage function
|
||||
Future<void> uploadimageupload_field(String ref, String refTableNmae,
|
||||
String selectedFilePath, Uint8List image_timageBytes) async {
|
||||
try {
|
||||
|
||||
final Uint8List fileBytes = image_timageBytes!;
|
||||
final mimeType = imageupload_fieldlookupMimeType(selectedFilePath);
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
'file': MultipartFile.fromBytes(
|
||||
fileBytes,
|
||||
filename: selectedFilePath
|
||||
.split('/')
|
||||
.last, // Get the file name from the path
|
||||
contentType: MediaType.parse(mimeType!),
|
||||
),
|
||||
});
|
||||
await repo.imageupload_fieldUpload(ref, refTableNmae, formData).then((value) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: "File uploaded successfully",
|
||||
toastType: ToastType.success);
|
||||
}).onError(
|
||||
(error, stackTrace) {
|
||||
print("error--$error");
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload file", toastType: ToastType.error);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
print('Error occurred during form submission: $error');
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the lookupMimeType function if needed
|
||||
String imageupload_fieldlookupMimeType(String filePath) {
|
||||
final ext = filePath.split('.').last;
|
||||
switch (ext) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'pdf':
|
||||
return 'application/pdf';
|
||||
// Add more cases for other file types as needed
|
||||
default:
|
||||
return 'application/octet-stream'; // Default MIME type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Helper method to upload multiple image files
|
||||
Future<void> _uploadvideo_field(
|
||||
String responseId, List<dynamic> Files) async {
|
||||
try {
|
||||
for (var File in Files) {
|
||||
if (File is Map<String, dynamic> &&
|
||||
File.containsKey('path')) {
|
||||
String filePath = File['path'];
|
||||
Uint8List fileBytes = File['bytes'];
|
||||
|
||||
// Upload each image file
|
||||
await uploadvideo_field(
|
||||
responseId, 'Forma', filePath, fileBytes);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
print('Error uploading files: $error');
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload images", toastType: ToastType.error);
|
||||
}
|
||||
}
|
||||
// Modify the uploadvideo_fieldimage function
|
||||
Future<void> uploadvideo_field(String ref, String refTableNmae,
|
||||
String selectedFilePath, Uint8List image_timageBytes) async {
|
||||
try {
|
||||
|
||||
final Uint8List fileBytes = image_timageBytes!;
|
||||
final mimeType = video_fieldlookupMimeType(selectedFilePath);
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
'file': MultipartFile.fromBytes(
|
||||
fileBytes,
|
||||
filename: selectedFilePath
|
||||
.split('/')
|
||||
.last, // Get the file name from the path
|
||||
contentType: MediaType.parse(mimeType!),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
|
||||
await repo.video_fieldUpload(ref, refTableNmae, formData).then((value) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: "File uploaded successfully",
|
||||
toastType: ToastType.success);
|
||||
}).onError(
|
||||
(error, stackTrace) {
|
||||
print("error--$error");
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload file", toastType: ToastType.error);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
print('Error occurred during form submission: $error');
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the lookupMimeType function if needed
|
||||
String video_fieldlookupMimeType(String filePath) {
|
||||
final ext = filePath.split('.').last.toLowerCase();
|
||||
switch (ext) {
|
||||
case 'mp4':
|
||||
return 'video/mp4';
|
||||
case 'mov':
|
||||
return 'video/quicktime';
|
||||
case 'avi':
|
||||
return 'video/x-msvideo';
|
||||
case 'wmv':
|
||||
return 'video/x-ms-wmv';
|
||||
case 'flv':
|
||||
return 'video/x-flv';
|
||||
case 'mkv':
|
||||
return 'video/x-matroska';
|
||||
// Add more cases for other file types as needed
|
||||
default:
|
||||
return 'application/octet-stream'; // Default MIME type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Helper method to upload multiple image files
|
||||
Future<void> _uploadaudio_field(
|
||||
String responseId, List<dynamic> Files) async {
|
||||
try {
|
||||
for (var File in Files) {
|
||||
if (File is Map<String, dynamic> &&
|
||||
File.containsKey('path')) {
|
||||
String filePath = File['path'];
|
||||
Uint8List fileBytes = File['bytes'];
|
||||
|
||||
// Upload each image file
|
||||
await uploadaudio_field(
|
||||
responseId, 'Forma', filePath, fileBytes);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
print('Error uploading files: $error');
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload images", toastType: ToastType.error);
|
||||
}
|
||||
}
|
||||
// Modify the uploadaudio_fieldimage function
|
||||
Future<void> uploadaudio_field(String ref, String refTableNmae,
|
||||
String selectedFilePath, Uint8List image_timageBytes) async {
|
||||
try {
|
||||
|
||||
final Uint8List fileBytes = image_timageBytes!;
|
||||
final mimeType = audio_fieldlookupMimeType(selectedFilePath);
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
'file': MultipartFile.fromBytes(
|
||||
fileBytes,
|
||||
filename: selectedFilePath
|
||||
.split('/')
|
||||
.last, // Get the file name from the path
|
||||
contentType: MediaType.parse(mimeType!),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
await repo.audio_fieldUpload(ref, refTableNmae, formData).then((value) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: "File uploaded successfully",
|
||||
toastType: ToastType.success);
|
||||
}).onError(
|
||||
(error, stackTrace) {
|
||||
print("error--$error");
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload file", toastType: ToastType.error);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
print('Error occurred during form submission: $error');
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the lookupMimeType function if needed
|
||||
String audio_fieldlookupMimeType(String filePath) {
|
||||
final ext = filePath.split('.').last.toLowerCase();
|
||||
switch (ext) {
|
||||
case 'mp3':
|
||||
return 'audio/mpeg';
|
||||
case 'wav':
|
||||
return 'audio/wav';
|
||||
case 'm4a':
|
||||
return 'audio/mp4';
|
||||
case 'flac':
|
||||
return 'audio/flac';
|
||||
// Add more cases for other audio formats as needed
|
||||
default:
|
||||
return 'application/octet-stream'; // Default MIME type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
2
testflutter016-testfldb-d/authsec_mysql/mysql/wf_table/wf_table.sql
Executable file
2
testflutter016-testfldb-d/authsec_mysql/mysql/wf_table/wf_table.sql
Executable file
@ -0,0 +1,2 @@
|
||||
CREATE TABLE testfldb.Forma(id BIGINT NOT NULL AUTO_INCREMENT, radio_field VARCHAR(400), a bit(1), video_field VARCHAR(400), b bit(1), currency VARCHAR(400), qrcode_field VARCHAR(400), fileupload_field VARCHAR(400), imageupload_field VARCHAR(400), audio_field VARCHAR(400), barcode_field VARCHAR(400), name VARCHAR(400), PRIMARY KEY (id));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user