build_app
This commit is contained in:
+6
@@ -80,6 +80,12 @@ public class BuilderService {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// ADD OTHER SERVICE
|
// ADD OTHER SERVICE
|
||||||
|
addCustomMenu( "World","World", "Transcations");
|
||||||
|
|
||||||
|
|
||||||
|
addCustomMenu( "Hello","Hello", "Transcations");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("dashboard and menu inserted...");
|
System.out.println("dashboard and menu inserted...");
|
||||||
|
|
||||||
|
|||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.realnet.wireframes.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.wireframes.Entity.Hello;
|
||||||
|
import com.realnet.wireframes.Services.HelloService ;
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/Hello")
|
||||||
|
@CrossOrigin("*")
|
||||||
|
@RestController
|
||||||
|
public class HelloController {
|
||||||
|
@Autowired
|
||||||
|
private HelloService Service;
|
||||||
|
|
||||||
|
@Value("${projectPath}")
|
||||||
|
private String projectPath;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/Hello")
|
||||||
|
public Hello Savedata(@RequestBody Hello data) {
|
||||||
|
Hello save = Service.Savedata(data) ;
|
||||||
|
|
||||||
|
System.out.println("data saved..." + save);
|
||||||
|
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
@PutMapping("/Hello/{id}")
|
||||||
|
public Hello update(@RequestBody Hello data,@PathVariable Integer id ) {
|
||||||
|
Hello update = Service.update(data,id);
|
||||||
|
System.out.println("data update..." + update);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
// get all with pagination
|
||||||
|
@GetMapping("/Hello/getall/page")
|
||||||
|
public Page<Hello> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||||
|
@RequestParam(value = "size", required = false) Integer size) {
|
||||||
|
Pageable paging = PageRequest.of(page, size);
|
||||||
|
Page<Hello> get = Service.getAllWithPagination(paging);
|
||||||
|
|
||||||
|
return get;
|
||||||
|
|
||||||
|
}
|
||||||
|
@GetMapping("/Hello")
|
||||||
|
public List<Hello> getdetails() {
|
||||||
|
List<Hello> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
// get all without authentication
|
||||||
|
|
||||||
|
@GetMapping("/token/Hello")
|
||||||
|
public List<Hello> getallwioutsec() {
|
||||||
|
List<Hello> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@GetMapping("/Hello/{id}")
|
||||||
|
public Hello getdetailsbyId(@PathVariable Integer id ) {
|
||||||
|
Hello get = Service.getdetailsbyId(id);
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@DeleteMapping("/Hello/{id}")
|
||||||
|
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||||
|
Service.delete_by_id(id);
|
||||||
|
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.realnet.wireframes.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.wireframes.Entity.World;
|
||||||
|
import com.realnet.wireframes.Services.WorldService ;
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/World")
|
||||||
|
@CrossOrigin("*")
|
||||||
|
@RestController
|
||||||
|
public class WorldController {
|
||||||
|
@Autowired
|
||||||
|
private WorldService Service;
|
||||||
|
|
||||||
|
@Value("${projectPath}")
|
||||||
|
private String projectPath;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/World")
|
||||||
|
public World Savedata(@RequestBody World data) {
|
||||||
|
World save = Service.Savedata(data) ;
|
||||||
|
|
||||||
|
System.out.println("data saved..." + save);
|
||||||
|
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
@PutMapping("/World/{id}")
|
||||||
|
public World update(@RequestBody World data,@PathVariable Integer id ) {
|
||||||
|
World update = Service.update(data,id);
|
||||||
|
System.out.println("data update..." + update);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
// get all with pagination
|
||||||
|
@GetMapping("/World/getall/page")
|
||||||
|
public Page<World> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||||
|
@RequestParam(value = "size", required = false) Integer size) {
|
||||||
|
Pageable paging = PageRequest.of(page, size);
|
||||||
|
Page<World> get = Service.getAllWithPagination(paging);
|
||||||
|
|
||||||
|
return get;
|
||||||
|
|
||||||
|
}
|
||||||
|
@GetMapping("/World")
|
||||||
|
public List<World> getdetails() {
|
||||||
|
List<World> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
// get all without authentication
|
||||||
|
|
||||||
|
@GetMapping("/token/World")
|
||||||
|
public List<World> getallwioutsec() {
|
||||||
|
List<World> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@GetMapping("/World/{id}")
|
||||||
|
public World getdetailsbyId(@PathVariable Integer id ) {
|
||||||
|
World get = Service.getdetailsbyId(id);
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@DeleteMapping("/World/{id}")
|
||||||
|
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||||
|
Service.delete_by_id(id);
|
||||||
|
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.realnet.wireframes.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.wireframes.Entity.Hello;
|
||||||
|
import com.realnet.wireframes.Services.HelloService ;
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/token/Hello")
|
||||||
|
@CrossOrigin("*")
|
||||||
|
@RestController
|
||||||
|
public class tokenFree_HelloController {
|
||||||
|
@Autowired
|
||||||
|
private HelloService Service;
|
||||||
|
|
||||||
|
@Value("${projectPath}")
|
||||||
|
private String projectPath;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/Hello")
|
||||||
|
public Hello Savedata(@RequestBody Hello data) {
|
||||||
|
Hello save = Service.Savedata(data) ;
|
||||||
|
|
||||||
|
System.out.println("data saved..." + save);
|
||||||
|
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
@PutMapping("/Hello/{id}")
|
||||||
|
public Hello update(@RequestBody Hello data,@PathVariable Integer id ) {
|
||||||
|
Hello update = Service.update(data,id);
|
||||||
|
System.out.println("data update..." + update);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
// get all with pagination
|
||||||
|
@GetMapping("/Hello/getall/page")
|
||||||
|
public Page<Hello> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||||
|
@RequestParam(value = "size", required = false) Integer size) {
|
||||||
|
Pageable paging = PageRequest.of(page, size);
|
||||||
|
Page<Hello> get = Service.getAllWithPagination(paging);
|
||||||
|
|
||||||
|
return get;
|
||||||
|
|
||||||
|
}
|
||||||
|
@GetMapping("/Hello")
|
||||||
|
public List<Hello> getdetails() {
|
||||||
|
List<Hello> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
// get all without authentication
|
||||||
|
|
||||||
|
@GetMapping("/token/Hello")
|
||||||
|
public List<Hello> getallwioutsec() {
|
||||||
|
List<Hello> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@GetMapping("/Hello/{id}")
|
||||||
|
public Hello getdetailsbyId(@PathVariable Integer id ) {
|
||||||
|
Hello get = Service.getdetailsbyId(id);
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@DeleteMapping("/Hello/{id}")
|
||||||
|
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||||
|
Service.delete_by_id(id);
|
||||||
|
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.realnet.wireframes.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.wireframes.Entity.World;
|
||||||
|
import com.realnet.wireframes.Services.WorldService ;
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/token/World")
|
||||||
|
@CrossOrigin("*")
|
||||||
|
@RestController
|
||||||
|
public class tokenFree_WorldController {
|
||||||
|
@Autowired
|
||||||
|
private WorldService Service;
|
||||||
|
|
||||||
|
@Value("${projectPath}")
|
||||||
|
private String projectPath;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/World")
|
||||||
|
public World Savedata(@RequestBody World data) {
|
||||||
|
World save = Service.Savedata(data) ;
|
||||||
|
|
||||||
|
System.out.println("data saved..." + save);
|
||||||
|
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
@PutMapping("/World/{id}")
|
||||||
|
public World update(@RequestBody World data,@PathVariable Integer id ) {
|
||||||
|
World update = Service.update(data,id);
|
||||||
|
System.out.println("data update..." + update);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
// get all with pagination
|
||||||
|
@GetMapping("/World/getall/page")
|
||||||
|
public Page<World> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||||
|
@RequestParam(value = "size", required = false) Integer size) {
|
||||||
|
Pageable paging = PageRequest.of(page, size);
|
||||||
|
Page<World> get = Service.getAllWithPagination(paging);
|
||||||
|
|
||||||
|
return get;
|
||||||
|
|
||||||
|
}
|
||||||
|
@GetMapping("/World")
|
||||||
|
public List<World> getdetails() {
|
||||||
|
List<World> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
// get all without authentication
|
||||||
|
|
||||||
|
@GetMapping("/token/World")
|
||||||
|
public List<World> getallwioutsec() {
|
||||||
|
List<World> get = Service.getdetails();
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@GetMapping("/World/{id}")
|
||||||
|
public World getdetailsbyId(@PathVariable Integer id ) {
|
||||||
|
World get = Service.getdetailsbyId(id);
|
||||||
|
return get;
|
||||||
|
}
|
||||||
|
@DeleteMapping("/World/{id}")
|
||||||
|
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||||
|
Service.delete_by_id(id);
|
||||||
|
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.realnet.wireframes.Entity;
|
||||||
|
import lombok.*;
|
||||||
|
import com.realnet.WhoColumn.Entity.Extension;
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class Hello extends Extension {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private int number_fieldn;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.realnet.wireframes.Entity;
|
||||||
|
import lombok.*;
|
||||||
|
import com.realnet.WhoColumn.Entity.Extension;
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class World extends Extension {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package com.realnet.wireframes.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.wireframes.Entity.Hello;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface HelloRepository extends JpaRepository<Hello, Integer> {
|
||||||
|
|
||||||
|
@Query(value = "select * from hello where created_by=?1", nativeQuery = true)
|
||||||
|
List<Hello> findAll(Long creayedBy);
|
||||||
|
|
||||||
|
@Query(value = "select * from hello where created_by=?1", nativeQuery = true)
|
||||||
|
Page<Hello> findAll( Long creayedBy,Pageable page);
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package com.realnet.wireframes.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.wireframes.Entity.World;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface WorldRepository extends JpaRepository<World, Integer> {
|
||||||
|
|
||||||
|
@Query(value = "select * from world where created_by=?1", nativeQuery = true)
|
||||||
|
List<World> findAll(Long creayedBy);
|
||||||
|
|
||||||
|
@Query(value = "select * from world where created_by=?1", nativeQuery = true)
|
||||||
|
Page<World> findAll( Long creayedBy,Pageable page);
|
||||||
|
}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
package com.realnet.wireframes.Services;
|
||||||
|
import com.realnet.wireframes.Repository.HelloRepository;
|
||||||
|
import com.realnet.wireframes.Entity.Hello
|
||||||
|
;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 HelloService {
|
||||||
|
@Autowired
|
||||||
|
private HelloRepository Repository;
|
||||||
|
@Autowired
|
||||||
|
private AppUserServiceImpl userService;
|
||||||
|
@Autowired
|
||||||
|
private RealmService realmService;
|
||||||
|
|
||||||
|
public Hello Savedata(Hello data) {
|
||||||
|
|
||||||
|
|
||||||
|
data.setUpdatedBy(getUser().getUserId());
|
||||||
|
data.setCreatedBy(getUser().getUserId());
|
||||||
|
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||||
|
Hello save = Repository.save(data);
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get all with pagination
|
||||||
|
public Page<Hello> getAllWithPagination(Pageable page) {
|
||||||
|
return Repository.findAll( getUser().getUserId(),page);
|
||||||
|
}
|
||||||
|
public List<Hello> getdetails() {
|
||||||
|
List<Realm> realm = realmService.findByUserId(getUser().getUserId());
|
||||||
|
List<Hello> all = Repository.findAll(getUser().getUserId());
|
||||||
|
|
||||||
|
return all ; }
|
||||||
|
|
||||||
|
|
||||||
|
public Hello getdetailsbyId(Integer id) {
|
||||||
|
return Repository.findById(id).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void delete_by_id(Integer id) {
|
||||||
|
Repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Hello update(Hello data,Integer id) {
|
||||||
|
Hello old = Repository.findById(id).get();
|
||||||
|
old.setNumber_fieldn(data.getNumber_fieldn());
|
||||||
|
|
||||||
|
final Hello test = Repository.save(old);
|
||||||
|
data.setUpdatedBy(getUser().getUserId());
|
||||||
|
return test;}
|
||||||
|
|
||||||
|
|
||||||
|
public AppUser getUser() {
|
||||||
|
AppUser user = userService.getLoggedInUser();
|
||||||
|
return user;
|
||||||
|
|
||||||
|
}}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
package com.realnet.wireframes.Services;
|
||||||
|
import com.realnet.wireframes.Repository.WorldRepository;
|
||||||
|
import com.realnet.wireframes.Entity.World
|
||||||
|
;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 WorldService {
|
||||||
|
@Autowired
|
||||||
|
private WorldRepository Repository;
|
||||||
|
@Autowired
|
||||||
|
private AppUserServiceImpl userService;
|
||||||
|
@Autowired
|
||||||
|
private RealmService realmService;
|
||||||
|
|
||||||
|
public World Savedata(World data) {
|
||||||
|
|
||||||
|
|
||||||
|
data.setUpdatedBy(getUser().getUserId());
|
||||||
|
data.setCreatedBy(getUser().getUserId());
|
||||||
|
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||||
|
World save = Repository.save(data);
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get all with pagination
|
||||||
|
public Page<World> getAllWithPagination(Pageable page) {
|
||||||
|
return Repository.findAll( getUser().getUserId(),page);
|
||||||
|
}
|
||||||
|
public List<World> getdetails() {
|
||||||
|
List<Realm> realm = realmService.findByUserId(getUser().getUserId());
|
||||||
|
List<World> all = Repository.findAll(getUser().getUserId());
|
||||||
|
|
||||||
|
return all ; }
|
||||||
|
|
||||||
|
|
||||||
|
public World getdetailsbyId(Integer id) {
|
||||||
|
return Repository.findById(id).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void delete_by_id(Integer id) {
|
||||||
|
Repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public World update(World data,Integer id) {
|
||||||
|
World old = Repository.findById(id).get();
|
||||||
|
old.setName(data.getName());
|
||||||
|
|
||||||
|
final World test = Repository.save(old);
|
||||||
|
data.setUpdatedBy(getUser().getUserId());
|
||||||
|
return test;}
|
||||||
|
|
||||||
|
|
||||||
|
public AppUser getUser() {
|
||||||
|
AppUser user = userService.getLoggedInUser();
|
||||||
|
return user;
|
||||||
|
|
||||||
|
}}
|
||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:http_parser/http_parser.dart';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
import '../../../resources/api_constants.dart';
|
||||||
|
import '../../../LocalStorage/UniController.dart';
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
class helloApiService {
|
||||||
|
final String baseUrl = ApiConstants.baseUrl;
|
||||||
|
final Dio dio = Dio();
|
||||||
|
final UniController uniController = UniController();
|
||||||
|
|
||||||
|
Future<List<Map<String, dynamic>>> getEntities(String token) async {
|
||||||
|
try {
|
||||||
|
final response = uniController.getentities('Hello');
|
||||||
|
|
||||||
|
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(
|
||||||
|
String token, int page, int size) async {
|
||||||
|
try {
|
||||||
|
final List<Map<String, dynamic>> localEntities =
|
||||||
|
await uniController.getentities('Hello');
|
||||||
|
print('local com is $localEntities');
|
||||||
|
|
||||||
|
if (localEntities.isNotEmpty) {
|
||||||
|
final entities = (localEntities).cast<Map<String, dynamic>>();
|
||||||
|
|
||||||
|
return entities;
|
||||||
|
} else {
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
final response = await dio.get('$baseUrl/Hello/Hello');
|
||||||
|
final entities = (response.data as List).cast<Map<String, dynamic>>();
|
||||||
|
// final response = await dio.get(
|
||||||
|
// '$baseUrl/Hello/Hello/getall/page?page=$page&size=$size');
|
||||||
|
// final entities =
|
||||||
|
// (response.data['content'] as List).cast<Map<String, dynamic>>();
|
||||||
|
uniController.insertEntities(entities, 'Hello');
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to get all without pagination: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> createEntity(
|
||||||
|
String token, Map<String, dynamic> entity) async {
|
||||||
|
try {
|
||||||
|
print("in post api data is ... $entity");
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
final response =
|
||||||
|
await dio.post('$baseUrl/Hello/Hello', data: entity);
|
||||||
|
|
||||||
|
print(entity);
|
||||||
|
|
||||||
|
// Assuming the response is a Map<String, dynamic>
|
||||||
|
Map<String, dynamic> responseData = response.data;
|
||||||
|
|
||||||
|
return responseData;
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to create entity: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> updateEntity(
|
||||||
|
String token, int entityId, Map<String, dynamic> entity) async {
|
||||||
|
try {
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
await dio.put('$baseUrl/Hello/Hello/$entityId', data: entity);
|
||||||
|
print(entity);
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to update entity: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteEntity(String token, int entityId) async {
|
||||||
|
try {
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
await dio.delete('$baseUrl/Hello/Hello/$entityId');
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to delete entity: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+222
@@ -0,0 +1,222 @@
|
|||||||
|
// 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 '../../../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:mobile_scanner/mobile_scanner.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import 'Hello_api_service.dart';
|
||||||
|
import '../../../providers/token_manager.dart';
|
||||||
|
import 'package:dropdown_search/dropdown_search.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 'dart:io';
|
||||||
|
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
|
||||||
|
class helloCreateEntityScreen extends StatefulWidget {
|
||||||
|
const helloCreateEntityScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_helloCreateEntityScreenState createState() => _helloCreateEntityScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _helloCreateEntityScreenState extends State<helloCreateEntityScreen> {
|
||||||
|
final helloApiService apiService = helloApiService();
|
||||||
|
final Map<String, dynamic> formData = {};
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> performOCR() async {
|
||||||
|
try {
|
||||||
|
final ImagePicker _picker = ImagePicker();
|
||||||
|
|
||||||
|
// Show options for gallery or camera using a dialog
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Select Image Source'),
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: ListBody(
|
||||||
|
children: <Widget>[
|
||||||
|
GestureDetector(
|
||||||
|
child: const Text('Gallery'),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
final XFile? image =
|
||||||
|
await _picker.pickImage(source: ImageSource.gallery);
|
||||||
|
processImage(image);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
GestureDetector(
|
||||||
|
child: const Text('Camera'),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
final XFile? image =
|
||||||
|
await _picker.pickImage(source: ImageSource.camera);
|
||||||
|
processImage(image);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print("OCR Error: $e");
|
||||||
|
// Handle OCR errors here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final textRecognizer = TextRecognizer();
|
||||||
|
|
||||||
|
void processImage(XFile? image) async {
|
||||||
|
if (image == null) return; // User canceled image picking
|
||||||
|
|
||||||
|
final file = File(image.path);
|
||||||
|
|
||||||
|
final inputImage = InputImage.fromFile(file);
|
||||||
|
final recognizedText = await textRecognizer.processImage(inputImage);
|
||||||
|
|
||||||
|
StringBuffer extractedTextBuffer = StringBuffer();
|
||||||
|
for (TextBlock block in recognizedText.blocks) {
|
||||||
|
for (TextLine line in block.lines) {
|
||||||
|
extractedTextBuffer.write(line.text + ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
textRecognizer.close();
|
||||||
|
|
||||||
|
String extractedText = extractedTextBuffer.toString().trim();
|
||||||
|
|
||||||
|
// Now you can process the extracted text as needed
|
||||||
|
// For example, you can update the corresponding TextFormField with the extracted text
|
||||||
|
setState(() {
|
||||||
|
formData['description'] = extractedText;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: CustomAppBar(
|
||||||
|
height: getVerticalSize(49),
|
||||||
|
leadingWidth: 40,
|
||||||
|
leading: AppbarImage(
|
||||||
|
height: getSize(24),
|
||||||
|
width: getSize(24),
|
||||||
|
svgPath: ImageConstant.imgArrowleftBlueGray900,
|
||||||
|
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
centerTitle: true,
|
||||||
|
title: AppbarTitle(text: "Create Hello")),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(top: 19),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text("Number Fieldn",
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGilroyMedium16Bluegray900),
|
||||||
|
CustomTextFormField(
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))],
|
||||||
|
// ValidationProperties
|
||||||
|
|
||||||
|
hintText: "Enter Number Fieldn",
|
||||||
|
onsaved: (value) => formData['number_fieldn'] = value,
|
||||||
|
margin: getMargin(top: 6))
|
||||||
|
])),
|
||||||
|
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
CustomButton(
|
||||||
|
height: getVerticalSize(50),
|
||||||
|
text: "Submit",
|
||||||
|
margin: getMargin(top: 24, bottom: 5),
|
||||||
|
onTap: () async {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
try {
|
||||||
|
print(formData);
|
||||||
|
Map<String, dynamic> createdEntity = await apiService.createEntity(token!, formData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
} catch (e) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to create Hello: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+560
@@ -0,0 +1,560 @@
|
|||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'Hello_api_service.dart';
|
||||||
|
import 'Hello_create_entity_screen.dart';
|
||||||
|
import 'Hello_update_entity_screen.dart';
|
||||||
|
import '../../../providers/token_manager.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:fluttertoast/fluttertoast.dart';
|
||||||
|
|
||||||
|
class hello_entity_list_screen extends StatefulWidget {
|
||||||
|
static const String routeName = '/entity-list';
|
||||||
|
|
||||||
|
@override
|
||||||
|
_hello_entity_list_screenState createState() => _hello_entity_list_screenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _hello_entity_list_screenState extends State<hello_entity_list_screen> {
|
||||||
|
|
||||||
|
final helloApiService apiService = helloApiService();
|
||||||
|
List<Map<String, dynamic>> entities = [];
|
||||||
|
List<Map<String, dynamic>> filteredEntities = [];
|
||||||
|
List<Map<String, dynamic>> serachEntities = [];
|
||||||
|
|
||||||
|
bool showCardView = true; // Add this variable to control the view mode
|
||||||
|
TextEditingController searchController = TextEditingController();
|
||||||
|
late stt.SpeechToText _speech;
|
||||||
|
|
||||||
|
bool isLoading = false; // Add this variable to track loading state
|
||||||
|
int currentPage = 0;
|
||||||
|
int pageSize = 10; // Adjust this based on your backend API
|
||||||
|
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_speech = stt.SpeechToText();
|
||||||
|
super.initState();
|
||||||
|
fetchEntities();
|
||||||
|
_scrollController.addListener(_scrollListener);
|
||||||
|
fetchwithoutpaging();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> fetchwithoutpaging() async {
|
||||||
|
try {
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
if (token != null) {
|
||||||
|
final fetchedEntities =
|
||||||
|
await apiService.getEntities(token!);
|
||||||
|
print('data is $fetchedEntities');
|
||||||
|
setState(() {
|
||||||
|
serachEntities = fetchedEntities; // Update only filteredEntities
|
||||||
|
});
|
||||||
|
print('Hello entity is .. $serachEntities');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to fetch Hello: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Future<void> fetchEntities() async {
|
||||||
|
try {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
if (token != null) {
|
||||||
|
|
||||||
|
final fetchedEntities =
|
||||||
|
await apiService.getAllWithPagination(token, currentPage, pageSize);
|
||||||
|
print(' data is $fetchedEntities');
|
||||||
|
setState(() {
|
||||||
|
entities.addAll(fetchedEntities); // Add new data to the existing list
|
||||||
|
filteredEntities = entities.toList(); // Update only filteredEntities
|
||||||
|
currentPage++;
|
||||||
|
});
|
||||||
|
|
||||||
|
print(' entity is .. $filteredEntities');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to fetch Hello data: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scrollListener() {
|
||||||
|
if (_scrollController.position.pixels ==
|
||||||
|
_scrollController.position.maxScrollExtent) {
|
||||||
|
fetchEntities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteEntity(Map<String, dynamic> entity) async {
|
||||||
|
try {
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
await apiService.deleteEntity(token!, entity['id']);
|
||||||
|
setState(() {
|
||||||
|
entities.remove(entity);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to delete entity: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _searchEntities(String keyword) {
|
||||||
|
setState(() {
|
||||||
|
filteredEntities = serachEntities
|
||||||
|
.where((entity) =>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
entity['number_fieldn'].toString().toLowerCase().contains(keyword.toLowerCase())
|
||||||
|
|
||||||
|
|
||||||
|
).toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startListening() async {
|
||||||
|
if (!_speech.isListening) {
|
||||||
|
bool available = await _speech.initialize(
|
||||||
|
onStatus: (status) {
|
||||||
|
print('Speech recognition status: $status');
|
||||||
|
},
|
||||||
|
onError: (error) {
|
||||||
|
print('Speech recognition error: $error');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (available) {
|
||||||
|
_speech.listen(
|
||||||
|
onResult: (result) {
|
||||||
|
if (result.finalResult) {
|
||||||
|
searchController.text = result.recognizedWords;
|
||||||
|
_searchEntities(result.recognizedWords);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _stopListening() {
|
||||||
|
if (_speech.isListening) {
|
||||||
|
_speech.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_speech.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
onTapArrowleft1(BuildContext context) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: CustomAppBar(
|
||||||
|
height: getVerticalSize(49),
|
||||||
|
leadingWidth: 40,
|
||||||
|
leading: AppbarImage(
|
||||||
|
height: getSize(24),
|
||||||
|
width: getSize(24),
|
||||||
|
svgPath: ImageConstant.imgArrowleft,
|
||||||
|
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||||
|
onTap: () {
|
||||||
|
onTapArrowleft1(context);
|
||||||
|
}),
|
||||||
|
centerTitle: true,
|
||||||
|
title: AppbarTitle(text: " Hello"),
|
||||||
|
actions: [
|
||||||
|
Switch(
|
||||||
|
activeColor: Colors.greenAccent,
|
||||||
|
inactiveThumbColor: Colors.white,
|
||||||
|
value: showCardView,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
showCardView = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: RefreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
currentPage = 1;
|
||||||
|
entities.clear();
|
||||||
|
await fetchEntities();
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: TextField(
|
||||||
|
controller: searchController,
|
||||||
|
onChanged: (value) {
|
||||||
|
_searchEntities(value);
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Search...',
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey[200],
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: const Icon(Icons.mic),
|
||||||
|
onPressed: () {
|
||||||
|
_startListening();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: filteredEntities.length + (isLoading ? 1 : 0),
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
if (index < filteredEntities.length) {
|
||||||
|
final entity = filteredEntities[index];
|
||||||
|
return _buildListItem(entity);
|
||||||
|
} else {
|
||||||
|
// Display the loading indicator at the bottom when new data is loading
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.all(8.0),
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
controller: _scrollController,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => helloCreateEntityScreen(),
|
||||||
|
),
|
||||||
|
).then((_) {
|
||||||
|
fetchEntities();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildListItem(Map<String, dynamic> entity) {
|
||||||
|
return showCardView ? _buildCardView(entity) : _buildNormalView(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Function to build card view for a list item
|
||||||
|
Widget _buildCardView(Map<String, dynamic> entity) {
|
||||||
|
return Card(
|
||||||
|
elevation: 2,
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||||
|
child: _buildNormalView(entity))
|
||||||
|
; }
|
||||||
|
|
||||||
|
// Function to build normal view for a list item
|
||||||
|
|
||||||
|
// Function to build normal view for a list item
|
||||||
|
|
||||||
|
Widget _buildNormalView(Map<String, dynamic> entity) {
|
||||||
|
final values = entity.values.elementAt(21) ?? 'Authsec';
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: Container(
|
||||||
|
padding: getPadding(
|
||||||
|
left: 16,
|
||||||
|
top: 5,
|
||||||
|
right: 5,
|
||||||
|
bottom: 17,
|
||||||
|
),
|
||||||
|
decoration: AppDecoration.outlineGray70011.copyWith(
|
||||||
|
borderRadius: BorderRadiusStyle.roundedBorder6,
|
||||||
|
color: Colors.grey[100]),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(
|
||||||
|
//right: 13,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: MediaQuery.of(context).size.width * 0.30,
|
||||||
|
margin: getMargin(
|
||||||
|
left: 8,
|
||||||
|
top: 3,
|
||||||
|
bottom: 1,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
entity['id'].toString(),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGreenSemiBold16,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.more_vert,
|
||||||
|
color: Colors.black,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
itemBuilder: (BuildContext context) {
|
||||||
|
return [
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'edit',
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.edit,
|
||||||
|
size: 16, // Adjust the icon size as needed
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Edit',
|
||||||
|
style: AppStyle
|
||||||
|
.txtGilroySemiBold16, // Adjust the text size as needed
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'delete',
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.delete,
|
||||||
|
size: 16, // Adjust the icon size as needed
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Delete',
|
||||||
|
style: AppStyle
|
||||||
|
.txtGilroySemiBold16, // Adjust the text size as needed
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
onSelected: (String value) {
|
||||||
|
if (value == 'edit') {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
helloUpdateEntityScreen(entity: entity),
|
||||||
|
),
|
||||||
|
).then((_) {
|
||||||
|
fetchEntities();
|
||||||
|
});
|
||||||
|
} else if (value == 'delete') {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Confirm Deletion'),
|
||||||
|
content: const Text(
|
||||||
|
'Are you sure you want to delete?'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Delete'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
deleteEntity(entity)
|
||||||
|
.then((value) => {fetchEntities()});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(
|
||||||
|
top: 10,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Number Fieldn : ",
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGilroyMedium16,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
entity['number_fieldn'].toString() ?? 'No Number Fieldn Available',
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGilroyMedium16Bluegray900,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildLeadingIcon(String title) {
|
||||||
|
return CircleAvatar(
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
child: Text(
|
||||||
|
title.isNotEmpty ? title[0].toUpperCase() : 'NA',
|
||||||
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showAdditionalFieldsDialog(
|
||||||
|
BuildContext context,
|
||||||
|
Map<String, dynamic> entity,
|
||||||
|
) {
|
||||||
|
final dateFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
|
||||||
|
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Additional Fields'),
|
||||||
|
content: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Created At: ${_formatTimestamp(entity['createdAt'], dateFormat)}'),
|
||||||
|
Text('Created By: ${entity['createdBy'] ?? 'N/A'}'),
|
||||||
|
Text('Updated By: ${entity['updatedBy'] ?? 'N/A'}'),
|
||||||
|
Text(
|
||||||
|
'Updated At: ${_formatTimestamp(entity['updatedAt'], dateFormat)}'),
|
||||||
|
Text('Account ID: ${entity['accountId'] ?? 'N/A'}'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Close'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _formatTimestamp(dynamic timestamp, DateFormat dateFormat) {
|
||||||
|
if (timestamp is int) {
|
||||||
|
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||||
|
return dateFormat.format(dateTime);
|
||||||
|
} else if (timestamp is String) {
|
||||||
|
return timestamp;
|
||||||
|
} else {
|
||||||
|
return 'N/A';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+153
@@ -0,0 +1,153 @@
|
|||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
import 'dart:convert';
|
||||||
|
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 'package:flutter/material.dart';
|
||||||
|
import 'package:dropdown_search/dropdown_search.dart';
|
||||||
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import 'Hello_api_service.dart';
|
||||||
|
|
||||||
|
import 'dart:math';
|
||||||
|
import '../../../providers/token_manager.dart';
|
||||||
|
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
class helloUpdateEntityScreen extends StatefulWidget {
|
||||||
|
final Map<String, dynamic> entity;
|
||||||
|
|
||||||
|
|
||||||
|
helloUpdateEntityScreen({required this.entity});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_helloUpdateEntityScreenState createState() => _helloUpdateEntityScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _helloUpdateEntityScreenState extends State<helloUpdateEntityScreen> {
|
||||||
|
final helloApiService apiService = helloApiService();
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: CustomAppBar(
|
||||||
|
height: getVerticalSize(49),
|
||||||
|
leadingWidth: 40,
|
||||||
|
leading: AppbarImage(
|
||||||
|
height: getSize(24),
|
||||||
|
width: getSize(24),
|
||||||
|
svgPath: ImageConstant.imgArrowleftBlueGray900,
|
||||||
|
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
centerTitle: true,
|
||||||
|
title: AppbarTitle(text: "Update Hello")),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(top: 19),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text("Number Fieldn",
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle
|
||||||
|
.txtGilroyMedium16Bluegray900),
|
||||||
|
CustomTextFormField(
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
hintText: "Enter Number Fieldn",
|
||||||
|
initialValue: widget.entity['number_fieldn'].toString(),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))],
|
||||||
|
|
||||||
|
|
||||||
|
// ValidationProperties
|
||||||
|
|
||||||
|
onsaved: (value) {
|
||||||
|
widget.entity['number_fieldn'] = value;
|
||||||
|
},
|
||||||
|
margin: getMargin(top: 6))
|
||||||
|
])),
|
||||||
|
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
|
||||||
|
CustomButton(
|
||||||
|
height: getVerticalSize(50),
|
||||||
|
text: "Update",
|
||||||
|
margin: getMargin(top: 24, bottom: 5),
|
||||||
|
onTap: () async {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
try {
|
||||||
|
await apiService.updateEntity(
|
||||||
|
token!,
|
||||||
|
widget.entity[
|
||||||
|
'id'], // Assuming 'id' is the key in your entity map
|
||||||
|
widget.entity);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
} catch (e) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content:
|
||||||
|
Text('Failed to update Hello: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:http_parser/http_parser.dart';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
import '../../../resources/api_constants.dart';
|
||||||
|
import '../../../LocalStorage/UniController.dart';
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
class worldApiService {
|
||||||
|
final String baseUrl = ApiConstants.baseUrl;
|
||||||
|
final Dio dio = Dio();
|
||||||
|
final UniController uniController = UniController();
|
||||||
|
|
||||||
|
Future<List<Map<String, dynamic>>> getEntities(String token) async {
|
||||||
|
try {
|
||||||
|
final response = uniController.getentities('World');
|
||||||
|
|
||||||
|
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(
|
||||||
|
String token, int page, int size) async {
|
||||||
|
try {
|
||||||
|
final List<Map<String, dynamic>> localEntities =
|
||||||
|
await uniController.getentities('World');
|
||||||
|
print('local com is $localEntities');
|
||||||
|
|
||||||
|
if (localEntities.isNotEmpty) {
|
||||||
|
final entities = (localEntities).cast<Map<String, dynamic>>();
|
||||||
|
|
||||||
|
return entities;
|
||||||
|
} else {
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
final response = await dio.get('$baseUrl/World/World');
|
||||||
|
final entities = (response.data as List).cast<Map<String, dynamic>>();
|
||||||
|
// final response = await dio.get(
|
||||||
|
// '$baseUrl/World/World/getall/page?page=$page&size=$size');
|
||||||
|
// final entities =
|
||||||
|
// (response.data['content'] as List).cast<Map<String, dynamic>>();
|
||||||
|
uniController.insertEntities(entities, 'World');
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to get all without pagination: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> createEntity(
|
||||||
|
String token, Map<String, dynamic> entity) async {
|
||||||
|
try {
|
||||||
|
print("in post api data is ... $entity");
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
final response =
|
||||||
|
await dio.post('$baseUrl/World/World', data: entity);
|
||||||
|
|
||||||
|
print(entity);
|
||||||
|
|
||||||
|
// Assuming the response is a Map<String, dynamic>
|
||||||
|
Map<String, dynamic> responseData = response.data;
|
||||||
|
|
||||||
|
return responseData;
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to create entity: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> updateEntity(
|
||||||
|
String token, int entityId, Map<String, dynamic> entity) async {
|
||||||
|
try {
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
await dio.put('$baseUrl/World/World/$entityId', data: entity);
|
||||||
|
print(entity);
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to update entity: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteEntity(String token, int entityId) async {
|
||||||
|
try {
|
||||||
|
dio.options.headers['Authorization'] = 'Bearer $token';
|
||||||
|
await dio.delete('$baseUrl/World/World/$entityId');
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Failed to delete entity: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+217
@@ -0,0 +1,217 @@
|
|||||||
|
// 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 '../../../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:mobile_scanner/mobile_scanner.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import 'World_api_service.dart';
|
||||||
|
import '../../../providers/token_manager.dart';
|
||||||
|
import 'package:dropdown_search/dropdown_search.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 'dart:io';
|
||||||
|
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
|
||||||
|
class worldCreateEntityScreen extends StatefulWidget {
|
||||||
|
const worldCreateEntityScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_worldCreateEntityScreenState createState() => _worldCreateEntityScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _worldCreateEntityScreenState extends State<worldCreateEntityScreen> {
|
||||||
|
final worldApiService apiService = worldApiService();
|
||||||
|
final Map<String, dynamic> formData = {};
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> performOCR() async {
|
||||||
|
try {
|
||||||
|
final ImagePicker _picker = ImagePicker();
|
||||||
|
|
||||||
|
// Show options for gallery or camera using a dialog
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Select Image Source'),
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: ListBody(
|
||||||
|
children: <Widget>[
|
||||||
|
GestureDetector(
|
||||||
|
child: const Text('Gallery'),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
final XFile? image =
|
||||||
|
await _picker.pickImage(source: ImageSource.gallery);
|
||||||
|
processImage(image);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
GestureDetector(
|
||||||
|
child: const Text('Camera'),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
final XFile? image =
|
||||||
|
await _picker.pickImage(source: ImageSource.camera);
|
||||||
|
processImage(image);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print("OCR Error: $e");
|
||||||
|
// Handle OCR errors here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final textRecognizer = TextRecognizer();
|
||||||
|
|
||||||
|
void processImage(XFile? image) async {
|
||||||
|
if (image == null) return; // User canceled image picking
|
||||||
|
|
||||||
|
final file = File(image.path);
|
||||||
|
|
||||||
|
final inputImage = InputImage.fromFile(file);
|
||||||
|
final recognizedText = await textRecognizer.processImage(inputImage);
|
||||||
|
|
||||||
|
StringBuffer extractedTextBuffer = StringBuffer();
|
||||||
|
for (TextBlock block in recognizedText.blocks) {
|
||||||
|
for (TextLine line in block.lines) {
|
||||||
|
extractedTextBuffer.write(line.text + ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
textRecognizer.close();
|
||||||
|
|
||||||
|
String extractedText = extractedTextBuffer.toString().trim();
|
||||||
|
|
||||||
|
// Now you can process the extracted text as needed
|
||||||
|
// For example, you can update the corresponding TextFormField with the extracted text
|
||||||
|
setState(() {
|
||||||
|
formData['description'] = extractedText;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: CustomAppBar(
|
||||||
|
height: getVerticalSize(49),
|
||||||
|
leadingWidth: 40,
|
||||||
|
leading: AppbarImage(
|
||||||
|
height: getSize(24),
|
||||||
|
width: getSize(24),
|
||||||
|
svgPath: ImageConstant.imgArrowleftBlueGray900,
|
||||||
|
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
centerTitle: true,
|
||||||
|
title: AppbarTitle(text: "Create World")),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(top: 18),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text("Name",
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.fieldlabel),
|
||||||
|
CustomTextFormField(
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
hintText: "Please Enter Name",
|
||||||
|
onsaved: (value) => formData['name'] = value,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
CustomButton(
|
||||||
|
height: getVerticalSize(50),
|
||||||
|
text: "Submit",
|
||||||
|
margin: getMargin(top: 24, bottom: 5),
|
||||||
|
onTap: () async {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
try {
|
||||||
|
print(formData);
|
||||||
|
Map<String, dynamic> createdEntity = await apiService.createEntity(token!, formData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
} catch (e) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to create World: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+560
@@ -0,0 +1,560 @@
|
|||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'World_api_service.dart';
|
||||||
|
import 'World_create_entity_screen.dart';
|
||||||
|
import 'World_update_entity_screen.dart';
|
||||||
|
import '../../../providers/token_manager.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:fluttertoast/fluttertoast.dart';
|
||||||
|
|
||||||
|
class world_entity_list_screen extends StatefulWidget {
|
||||||
|
static const String routeName = '/entity-list';
|
||||||
|
|
||||||
|
@override
|
||||||
|
_world_entity_list_screenState createState() => _world_entity_list_screenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _world_entity_list_screenState extends State<world_entity_list_screen> {
|
||||||
|
|
||||||
|
final worldApiService apiService = worldApiService();
|
||||||
|
List<Map<String, dynamic>> entities = [];
|
||||||
|
List<Map<String, dynamic>> filteredEntities = [];
|
||||||
|
List<Map<String, dynamic>> serachEntities = [];
|
||||||
|
|
||||||
|
bool showCardView = true; // Add this variable to control the view mode
|
||||||
|
TextEditingController searchController = TextEditingController();
|
||||||
|
late stt.SpeechToText _speech;
|
||||||
|
|
||||||
|
bool isLoading = false; // Add this variable to track loading state
|
||||||
|
int currentPage = 0;
|
||||||
|
int pageSize = 10; // Adjust this based on your backend API
|
||||||
|
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_speech = stt.SpeechToText();
|
||||||
|
super.initState();
|
||||||
|
fetchEntities();
|
||||||
|
_scrollController.addListener(_scrollListener);
|
||||||
|
fetchwithoutpaging();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> fetchwithoutpaging() async {
|
||||||
|
try {
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
if (token != null) {
|
||||||
|
final fetchedEntities =
|
||||||
|
await apiService.getEntities(token!);
|
||||||
|
print('data is $fetchedEntities');
|
||||||
|
setState(() {
|
||||||
|
serachEntities = fetchedEntities; // Update only filteredEntities
|
||||||
|
});
|
||||||
|
print('World entity is .. $serachEntities');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to fetch World: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Future<void> fetchEntities() async {
|
||||||
|
try {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
if (token != null) {
|
||||||
|
|
||||||
|
final fetchedEntities =
|
||||||
|
await apiService.getAllWithPagination(token, currentPage, pageSize);
|
||||||
|
print(' data is $fetchedEntities');
|
||||||
|
setState(() {
|
||||||
|
entities.addAll(fetchedEntities); // Add new data to the existing list
|
||||||
|
filteredEntities = entities.toList(); // Update only filteredEntities
|
||||||
|
currentPage++;
|
||||||
|
});
|
||||||
|
|
||||||
|
print(' entity is .. $filteredEntities');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to fetch World data: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scrollListener() {
|
||||||
|
if (_scrollController.position.pixels ==
|
||||||
|
_scrollController.position.maxScrollExtent) {
|
||||||
|
fetchEntities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteEntity(Map<String, dynamic> entity) async {
|
||||||
|
try {
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
await apiService.deleteEntity(token!, entity['id']);
|
||||||
|
setState(() {
|
||||||
|
entities.remove(entity);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content: Text('Failed to delete entity: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _searchEntities(String keyword) {
|
||||||
|
setState(() {
|
||||||
|
filteredEntities = serachEntities
|
||||||
|
.where((entity) =>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
entity['name'].toString().toLowerCase().contains(keyword.toLowerCase())
|
||||||
|
|
||||||
|
|
||||||
|
).toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startListening() async {
|
||||||
|
if (!_speech.isListening) {
|
||||||
|
bool available = await _speech.initialize(
|
||||||
|
onStatus: (status) {
|
||||||
|
print('Speech recognition status: $status');
|
||||||
|
},
|
||||||
|
onError: (error) {
|
||||||
|
print('Speech recognition error: $error');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (available) {
|
||||||
|
_speech.listen(
|
||||||
|
onResult: (result) {
|
||||||
|
if (result.finalResult) {
|
||||||
|
searchController.text = result.recognizedWords;
|
||||||
|
_searchEntities(result.recognizedWords);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _stopListening() {
|
||||||
|
if (_speech.isListening) {
|
||||||
|
_speech.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_speech.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
onTapArrowleft1(BuildContext context) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: CustomAppBar(
|
||||||
|
height: getVerticalSize(49),
|
||||||
|
leadingWidth: 40,
|
||||||
|
leading: AppbarImage(
|
||||||
|
height: getSize(24),
|
||||||
|
width: getSize(24),
|
||||||
|
svgPath: ImageConstant.imgArrowleft,
|
||||||
|
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||||
|
onTap: () {
|
||||||
|
onTapArrowleft1(context);
|
||||||
|
}),
|
||||||
|
centerTitle: true,
|
||||||
|
title: AppbarTitle(text: " World"),
|
||||||
|
actions: [
|
||||||
|
Switch(
|
||||||
|
activeColor: Colors.greenAccent,
|
||||||
|
inactiveThumbColor: Colors.white,
|
||||||
|
value: showCardView,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
showCardView = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: RefreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
currentPage = 1;
|
||||||
|
entities.clear();
|
||||||
|
await fetchEntities();
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: TextField(
|
||||||
|
controller: searchController,
|
||||||
|
onChanged: (value) {
|
||||||
|
_searchEntities(value);
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Search...',
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey[200],
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: const Icon(Icons.mic),
|
||||||
|
onPressed: () {
|
||||||
|
_startListening();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: filteredEntities.length + (isLoading ? 1 : 0),
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
if (index < filteredEntities.length) {
|
||||||
|
final entity = filteredEntities[index];
|
||||||
|
return _buildListItem(entity);
|
||||||
|
} else {
|
||||||
|
// Display the loading indicator at the bottom when new data is loading
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.all(8.0),
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
controller: _scrollController,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => worldCreateEntityScreen(),
|
||||||
|
),
|
||||||
|
).then((_) {
|
||||||
|
fetchEntities();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildListItem(Map<String, dynamic> entity) {
|
||||||
|
return showCardView ? _buildCardView(entity) : _buildNormalView(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Function to build card view for a list item
|
||||||
|
Widget _buildCardView(Map<String, dynamic> entity) {
|
||||||
|
return Card(
|
||||||
|
elevation: 2,
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||||
|
child: _buildNormalView(entity))
|
||||||
|
; }
|
||||||
|
|
||||||
|
// Function to build normal view for a list item
|
||||||
|
|
||||||
|
// Function to build normal view for a list item
|
||||||
|
|
||||||
|
Widget _buildNormalView(Map<String, dynamic> entity) {
|
||||||
|
final values = entity.values.elementAt(21) ?? 'Authsec';
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: Container(
|
||||||
|
padding: getPadding(
|
||||||
|
left: 16,
|
||||||
|
top: 5,
|
||||||
|
right: 5,
|
||||||
|
bottom: 17,
|
||||||
|
),
|
||||||
|
decoration: AppDecoration.outlineGray70011.copyWith(
|
||||||
|
borderRadius: BorderRadiusStyle.roundedBorder6,
|
||||||
|
color: Colors.grey[100]),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(
|
||||||
|
//right: 13,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: MediaQuery.of(context).size.width * 0.30,
|
||||||
|
margin: getMargin(
|
||||||
|
left: 8,
|
||||||
|
top: 3,
|
||||||
|
bottom: 1,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
entity['id'].toString(),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGreenSemiBold16,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.more_vert,
|
||||||
|
color: Colors.black,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
itemBuilder: (BuildContext context) {
|
||||||
|
return [
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'edit',
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.edit,
|
||||||
|
size: 16, // Adjust the icon size as needed
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Edit',
|
||||||
|
style: AppStyle
|
||||||
|
.txtGilroySemiBold16, // Adjust the text size as needed
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'delete',
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.delete,
|
||||||
|
size: 16, // Adjust the icon size as needed
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Delete',
|
||||||
|
style: AppStyle
|
||||||
|
.txtGilroySemiBold16, // Adjust the text size as needed
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
onSelected: (String value) {
|
||||||
|
if (value == 'edit') {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
worldUpdateEntityScreen(entity: entity),
|
||||||
|
),
|
||||||
|
).then((_) {
|
||||||
|
fetchEntities();
|
||||||
|
});
|
||||||
|
} else if (value == 'delete') {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Confirm Deletion'),
|
||||||
|
content: const Text(
|
||||||
|
'Are you sure you want to delete?'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Delete'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
deleteEntity(entity)
|
||||||
|
.then((value) => {fetchEntities()});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(
|
||||||
|
top: 10,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Name : ",
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGilroyMedium16,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
entity['name'] ?? 'No Name Available',
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style: AppStyle.txtGilroyMedium16Bluegray900,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildLeadingIcon(String title) {
|
||||||
|
return CircleAvatar(
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
child: Text(
|
||||||
|
title.isNotEmpty ? title[0].toUpperCase() : 'NA',
|
||||||
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showAdditionalFieldsDialog(
|
||||||
|
BuildContext context,
|
||||||
|
Map<String, dynamic> entity,
|
||||||
|
) {
|
||||||
|
final dateFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
|
||||||
|
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Additional Fields'),
|
||||||
|
content: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Created At: ${_formatTimestamp(entity['createdAt'], dateFormat)}'),
|
||||||
|
Text('Created By: ${entity['createdBy'] ?? 'N/A'}'),
|
||||||
|
Text('Updated By: ${entity['updatedBy'] ?? 'N/A'}'),
|
||||||
|
Text(
|
||||||
|
'Updated At: ${_formatTimestamp(entity['updatedAt'], dateFormat)}'),
|
||||||
|
Text('Account ID: ${entity['accountId'] ?? 'N/A'}'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('Close'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _formatTimestamp(dynamic timestamp, DateFormat dateFormat) {
|
||||||
|
if (timestamp is int) {
|
||||||
|
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||||
|
return dateFormat.format(dateTime);
|
||||||
|
} else if (timestamp is String) {
|
||||||
|
return timestamp;
|
||||||
|
} else {
|
||||||
|
return 'N/A';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
import 'dart:convert';
|
||||||
|
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 'package:flutter/material.dart';
|
||||||
|
import 'package:dropdown_search/dropdown_search.dart';
|
||||||
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import 'World_api_service.dart';
|
||||||
|
|
||||||
|
import 'dart:math';
|
||||||
|
import '../../../providers/token_manager.dart';
|
||||||
|
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
class worldUpdateEntityScreen extends StatefulWidget {
|
||||||
|
final Map<String, dynamic> entity;
|
||||||
|
|
||||||
|
|
||||||
|
worldUpdateEntityScreen({required this.entity});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_worldUpdateEntityScreenState createState() => _worldUpdateEntityScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _worldUpdateEntityScreenState extends State<worldUpdateEntityScreen> {
|
||||||
|
final worldApiService apiService = worldApiService();
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: CustomAppBar(
|
||||||
|
height: getVerticalSize(49),
|
||||||
|
leadingWidth: 40,
|
||||||
|
leading: AppbarImage(
|
||||||
|
height: getSize(24),
|
||||||
|
width: getSize(24),
|
||||||
|
svgPath: ImageConstant.imgArrowleftBlueGray900,
|
||||||
|
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
centerTitle: true,
|
||||||
|
title: AppbarTitle(text: "Update World")),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: getPadding(top: 18),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text("Name",
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
style:
|
||||||
|
AppStyle.txtGilroyMedium16Bluegray900),
|
||||||
|
CustomTextFormField(
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
hintText: "Please Enter Name",
|
||||||
|
initialValue: widget.entity['name'],
|
||||||
|
|
||||||
|
// ValidationProperties
|
||||||
|
onsaved: (value) => widget.entity['name'] = value,
|
||||||
|
margin: getMargin(top: 7))
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
CustomButton(
|
||||||
|
height: getVerticalSize(50),
|
||||||
|
text: "Update",
|
||||||
|
margin: getMargin(top: 24, bottom: 5),
|
||||||
|
onTap: () async {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final token = await TokenManager.getToken();
|
||||||
|
try {
|
||||||
|
await apiService.updateEntity(
|
||||||
|
token!,
|
||||||
|
widget.entity[
|
||||||
|
'id'], // Assuming 'id' is the key in your entity map
|
||||||
|
widget.entity);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
} catch (e) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Error'),
|
||||||
|
content:
|
||||||
|
Text('Failed to update World: $e'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: const Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,17 +2,101 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
class TableQuery {
|
class TableQuery {
|
||||||
Future<void> createOtherTable(Database db) async {
|
Future<void> createOtherTable(Database db) async {
|
||||||
// Table Query
|
// Table Query
|
||||||
|
|
||||||
|
_createWorld(db, 'World');
|
||||||
|
|
||||||
|
|
||||||
|
_createHello(db, 'Hello');
|
||||||
|
|
||||||
// OLD: _createGauravt2(db, 'Gauravt2'); // demo table from old template - disabled for clean base - by Azmat
|
// OLD: _createGauravt2(db, 'Gauravt2'); // demo table from old template - disabled for clean base - by Azmat
|
||||||
// OLD: _createGauravtest1(db, 'Gauravtest1'); // demo table from old template - disabled for clean base - by Azmat
|
// OLD: _createGauravtest1(db, 'Gauravtest1'); // demo table from old template - disabled for clean base - by Azmat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Table Query Data
|
// Table Query Data
|
||||||
|
|
||||||
|
Future<void> _createWorld(Database db, String tableName) async {
|
||||||
|
var tableExists = await _isTableExists(db, tableName);
|
||||||
|
if (!tableExists) {
|
||||||
|
print('$tableName making.....');
|
||||||
|
await db.execute(
|
||||||
|
'''
|
||||||
|
CREATE TABLE $tableName (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
accountId TEXT,
|
||||||
|
createdAt TEXT,
|
||||||
|
createdBy TEXT,
|
||||||
|
updatedAt TEXT,
|
||||||
|
updatedBy TEXT,
|
||||||
|
extn1 TEXT,
|
||||||
|
extn2 TEXT,
|
||||||
|
extn3 TEXT,
|
||||||
|
extn4 TEXT,
|
||||||
|
extn5 TEXT,
|
||||||
|
extn6 TEXT,
|
||||||
|
extn7 TEXT,
|
||||||
|
extn8 TEXT,
|
||||||
|
extn9 TEXT,
|
||||||
|
extn10 TEXT,
|
||||||
|
extn11 TEXT,
|
||||||
|
extn12 TEXT,
|
||||||
|
extn13 TEXT,
|
||||||
|
extn14 TEXT,
|
||||||
|
extn15 TEXT,
|
||||||
|
Name TEXT,
|
||||||
|
|
||||||
|
)''');
|
||||||
|
} else {
|
||||||
|
print('$tableName table exist');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> _createHello(Database db, String tableName) async {
|
||||||
|
var tableExists = await _isTableExists(db, tableName);
|
||||||
|
if (!tableExists) {
|
||||||
|
print('$tableName making.....');
|
||||||
|
await db.execute(
|
||||||
|
'''
|
||||||
|
CREATE TABLE $tableName (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
accountId TEXT,
|
||||||
|
createdAt TEXT,
|
||||||
|
createdBy TEXT,
|
||||||
|
updatedAt TEXT,
|
||||||
|
updatedBy TEXT,
|
||||||
|
extn1 TEXT,
|
||||||
|
extn2 TEXT,
|
||||||
|
extn3 TEXT,
|
||||||
|
extn4 TEXT,
|
||||||
|
extn5 TEXT,
|
||||||
|
extn6 TEXT,
|
||||||
|
extn7 TEXT,
|
||||||
|
extn8 TEXT,
|
||||||
|
extn9 TEXT,
|
||||||
|
extn10 TEXT,
|
||||||
|
extn11 TEXT,
|
||||||
|
extn12 TEXT,
|
||||||
|
extn13 TEXT,
|
||||||
|
extn14 TEXT,
|
||||||
|
extn15 TEXT,
|
||||||
|
Number_Fieldn INTEGER,
|
||||||
|
|
||||||
|
)''');
|
||||||
|
} else {
|
||||||
|
print('$tableName table exist');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<void> _createGauravt2(Database db, String tableName) async {
|
Future<void> _createGauravt2(Database db, String tableName) async {
|
||||||
var tableExists = await _isTableExists(db, tableName);
|
var tableExists = await _isTableExists(db, tableName);
|
||||||
if (!tableExists) {
|
if (!tableExists) {
|
||||||
|
|||||||
+40
@@ -1,3 +1,7 @@
|
|||||||
|
import '../../Entity/wireframes/World/World_entity_list_screen.dart';
|
||||||
|
|
||||||
|
import '../../Entity/wireframes/Hello/Hello_entity_list_screen.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -344,6 +348,42 @@ class _TabbedLayoutComponentState extends State<TabbedLayoutComponent> {
|
|||||||
),
|
),
|
||||||
|
|
||||||
// NEW MENU
|
// NEW MENU
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
//value: 'Option 1',
|
||||||
|
child: Text(
|
||||||
|
'World',
|
||||||
|
style: AppStyle.txtGilroySemiBold16,
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
world_entity_list_screen(), //go to get all entity
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Add your logic for menu 2 here
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
//value: 'Option 1',
|
||||||
|
child: Text(
|
||||||
|
'Hello',
|
||||||
|
style: AppStyle.txtGilroySemiBold16,
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
hello_entity_list_screen(), //go to get all entity
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Add your logic for menu 2 here
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
CREATE TABLE sep1515.Hello(id BIGINT NOT NULL AUTO_INCREMENT, number_fieldn int, PRIMARY KEY (id));
|
||||||
|
|
||||||
|
CREATE TABLE sep1515.World(id BIGINT NOT NULL AUTO_INCREMENT, name VARCHAR(400), PRIMARY KEY (id));
|
||||||
|
|
||||||
Reference in New Issue
Block a user