import 'package:flutter/material.dart';
import 'package:flutter_wallet/base/YSBase.dart';
import 'package:flutter_wallet/shop/view/YSExchangeRecordListItemView.dart';
import 'package:flutter_wallet/tools/YSColors.dart';
import 'package:flutter_wallet/tools/YSRefrehLoad.dart';
import 'package:flutter_wallet/tools/YSTools.dart';

class YSCrossRecord extends StatefulWidget {
  final Map item;
  const YSCrossRecord({Key? key, required this.item}) : super(key: key);

  @override
  YSCrossRecordState createState() => YSCrossRecordState();
}

class YSCrossRecordState extends State<YSCrossRecord> {
  List _array = [];
  @override
  Widget build(BuildContext context) {
    return YSBase(
      ysTitle: '跨链记录',
      ysChild: Container(
        width: ysWidth(context),
        height: ysHeight(context)-ysTOP(context)-60,
        color: Colors.white,
        child: YSRefreshLoad(
          url: 'cross-txs',
          request: {'from_addr':widget.item['address']},
          postData: (value) {
            _array = value;
            setState(() {});
          },
          child: SingleChildScrollView(
            child: ListView.separated(
              itemBuilder: (context,index){
                Map item = _array[index];
                return Padding(
                  padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
                  child: YSExchangeRecordListItemView(item: item)
                );
              },
              separatorBuilder: (context,index){
                return Divider(height: hsp(20),color: YSColors.backgroundColor(context),thickness: hsp(20),);
              },
              itemCount: _array.length,
              padding: const EdgeInsets.all(0),
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,
            ),
          ),
        ),
      ),
    );
  }
}

class YSCrossRecord2 extends StatefulWidget {
  const YSCrossRecord2({Key? key}) : super(key: key);

  @override
  YSCrossRecord2State createState() => YSCrossRecord2State();
}

class YSCrossRecord2State extends State<YSCrossRecord2> {
  List _array = [];
  @override
  Widget build(BuildContext context) {
    return YSBase(
      ysTitle: '兑换记录',
      ysChild: Container(
        width: ysWidth(context),
        height: ysHeight(context)-ysTOP(context)-60,
        color: Colors.white,
        child: YSRefreshLoad(
          url: 'transactions',
          request: {'chain_id':YSData().typeId,'address':YSData().wallet['public'],'type':0},
          postData: (value) {
            _array = value;
            setState(() {});
          },
          child: SingleChildScrollView(
            child: ListView.separated(
              itemBuilder: (context,index){
                Map item = _array[index];
                return Padding(
                    padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
                    child: YSExchangeRecordListItemView2(item: item)
                );
              },
              separatorBuilder: (context,index){
                return Divider(height: hsp(20),color: YSColors.backgroundColor(context),thickness: hsp(20),);
              },
              itemCount: _array.length,
              padding: const EdgeInsets.all(0),
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,
            ),
          ),
        ),
      ),
    );
  }
}
