YSPhoto.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/base/YSTools.dart';
  4. import 'base/YSBase.dart';
  5. import 'base/YSNetWorking.dart';
  6. class YSPhoto extends StatefulWidget {
  7. @override
  8. _YSPhotoState createState() => _YSPhotoState();
  9. }
  10. String timeSwitch(String timeStr){
  11. DateTime time = DateTime.parse(timeStr);
  12. return "${time.month.toString().padLeft(2,'0')}月";
  13. }
  14. class _YSPhotoState extends State<YSPhoto> {
  15. List dataArray = [];
  16. @override
  17. void initState() {
  18. Future.delayed(Duration(seconds: 0)).then((value){
  19. _getPhotoData();
  20. });
  21. super.initState();
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. // List dataArray = [{'time':'2020-07-08 15:32:41','photo':['0']},{'time':'2020-07-08 15:32:41','photo':['0','0']},{'time':'2020-07-08 15:32:41','photo':['0','0','0','0']},{'time':'2020-07-08 15:32:41','photo':['0']}
  26. // ,{'time':'2020-07-08 15:32:41','photo':['0','0','0','0','0','0','0','0','0','0']},{'time':'2020-07-08 15:32:41','photo':['0','0','0','0','0','0']}];
  27. return YSBase(
  28. ystitle: '相册',
  29. yschild: Container(
  30. height: MediaQuery.of(context).size.height-75,
  31. decoration: BoxDecoration(
  32. color: Colors.white,
  33. borderRadius: BorderRadius.only(topRight: Radius.circular(20),topLeft: Radius.circular(20))
  34. ),
  35. child: dataArray.length==0?Container(
  36. alignment: Alignment.center,
  37. child: Image.asset('lib/images/none.png',height: 200,width: 200,),
  38. ):ListView.builder(itemBuilder: (context,index){
  39. return Container(
  40. padding: EdgeInsets.only(left: 20,right: 20,top: 5,bottom: 5),
  41. child: Row(
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. children: [
  44. Text(timeSwitch(dataArray[index]['time']),style: TextStyle(fontSize: 18,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  45. Container(
  46. width: MediaQuery.of(context).size.width-150,
  47. height: dataArray[index]['covers'].length==0?0:dataArray[index]['covers'].length%3!=0?70.0*(((dataArray[index]['covers'].length)~/3)+1):70.0*((dataArray[index]['covers'].length)~/3),
  48. margin: EdgeInsets.only(left: 30),
  49. child: GridView.builder(
  50. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  51. crossAxisCount: 3,
  52. ),
  53. itemBuilder: (context,indexSub){
  54. return GestureDetector(
  55. onTap: (){
  56. Navigator.of(context).push(
  57. CupertinoPageRoute(builder: (context){
  58. return YSPhotoDetail(url: dataArray[index]['covers'][indexSub],);
  59. })
  60. );
  61. },
  62. behavior: HitTestBehavior.opaque,
  63. child: Container(
  64. height: 70,
  65. width: 70,
  66. margin: EdgeInsets.all(5),
  67. color: Color(0xFFEFEFEF),
  68. child: Image(image: NetworkImage('${dataArray[index]['covers'][indexSub]}'),fit: BoxFit.fill,height: double.infinity,width: double.infinity,),
  69. ),
  70. );
  71. },
  72. itemCount: dataArray[index]['covers'].length,
  73. physics: NeverScrollableScrollPhysics(),
  74. padding: EdgeInsets.all(0),
  75. ),
  76. )
  77. ],
  78. ),
  79. );
  80. },itemCount: dataArray.length,padding: EdgeInsets.only(top: 15,bottom: 15),),
  81. )
  82. ,
  83. );
  84. }
  85. _getPhotoData() async{
  86. Map dict = await ysRequestHttp(context, requestType.get, 'diary/album', {});
  87. if(dict!=null){
  88. setState(() {
  89. dataArray = dict['data']['data']??[];
  90. });
  91. }
  92. }
  93. }
  94. class YSPhotoDetail extends StatefulWidget {
  95. final String url;
  96. const YSPhotoDetail({Key key, this.url}) : super(key: key);
  97. @override
  98. _YSPhotoDetailState createState() => _YSPhotoDetailState();
  99. }
  100. class _YSPhotoDetailState extends State<YSPhotoDetail> {
  101. @override
  102. Widget build(BuildContext context) {
  103. return Scaffold(
  104. body: GestureDetector(
  105. onTap: (){
  106. Navigator.pop(context);
  107. },
  108. child: Container(
  109. color: Colors.black,
  110. width: ysWidth(context),
  111. height: ysHeight(context),
  112. child: Image.network(widget.url),
  113. ),
  114. ),
  115. );
  116. }
  117. }