flutter app untuk unitstock
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

88 linhas
2.6 KiB

  1. import 'dart:io';
  2. import 'dart:typed_data';
  3. import 'package:image_picker/image_picker.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:photo_view/photo_view.dart';
  7. import 'UnitModel.dart';
  8. import 'Util.dart';
  9. class PhotoViewer extends StatefulWidget {
  10. Uint8List byte;
  11. String id;
  12. List<jenisDrop> dropMenu;
  13. bool edit;
  14. String jenis;
  15. PhotoViewer(this.byte,{this.id,this.edit= true,this.dropMenu,this.jenis});
  16. // PhotoViewer({Key key}) : super(key: key);
  17. @override
  18. _PhotoViewerState createState() => _PhotoViewerState();
  19. }
  20. class _PhotoViewerState extends State<PhotoViewer> {
  21. Util util = new Util();
  22. String jenisImages;
  23. @override
  24. Widget build(BuildContext context) {
  25. return Column(
  26. children: <Widget>[
  27. Flexible(
  28. flex: 8,
  29. child: Container(
  30. child: Hero(
  31. tag: widget.id,
  32. child: PhotoView(
  33. imageProvider: MemoryImage(widget.byte),
  34. ),
  35. ),
  36. ),
  37. ),
  38. Expanded(
  39. flex: 1,
  40. child: Material(
  41. color: Colors.transparent,
  42. child: Container(
  43. child: Text(widget.jenis,style: TextStyle(color: Colors.white,fontSize: 18),),
  44. ),
  45. ),
  46. ),
  47. (widget.edit)?Flexible(
  48. flex: 1,
  49. child: Row(
  50. crossAxisAlignment: CrossAxisAlignment.center,
  51. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  52. children: <Widget>[
  53. TextButton(
  54. child: Text('Cancel'),
  55. style: TextButton.styleFrom(
  56. backgroundColor: Colors.red
  57. ),
  58. onPressed: (){Navigator.pop(context);},
  59. ),
  60. TextButton(
  61. child: Text('Change'),
  62. style: TextButton.styleFrom(
  63. backgroundColor: Colors.green
  64. ),
  65. onPressed: ()async{
  66. XFile temp = await ImagePicker().pickImage(source: ImageSource.camera,maxWidth: 800);
  67. if(temp!=null){
  68. util.showLoading(context);
  69. widget.byte = await temp.readAsBytes();
  70. setState(() {
  71. });
  72. await Future.delayed(Duration(seconds: 1));
  73. }
  74. Navigator.pop(context);
  75. if(temp!= null)Navigator.pop(context,{'byte':widget.byte});
  76. },
  77. ),
  78. ],
  79. ),
  80. ):Container()
  81. ],
  82. );
  83. }
  84. }