import 'package:flutter/material.dart';
import 'package:flutter_wallet/generated/l10n.dart';
import 'package:provider/provider.dart';

import '../base/YSBase.dart';
import '../tools/YSColors.dart';
import '../tools/YSTools.dart';

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

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

class YSSettingPriceState extends State<YSSettingPrice> {
  final List _list = [
    {'title':S.current.LVZHANGHONGDIE,'type':'1'},
    {'title':S.current.HONGZHANGLVDIE,'type':'2'}
  ];
  @override
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return YSBase(
      ysTitle: S.current.HANGQINGSHEZHI,
      ysChild: Consumer(
        builder: (context,YSPriceTypeNotifier value,child) {
          return Container(
            width: ysWidth(context),
            color: YSColors.containColor(context),
            child: ListView.separated(
              itemBuilder: (context,index){
                Map item = _list[index];
                bool isChoose = item['type']==YSUserRecord().priceType;
                return GestureDetector(
                  onTap: (){
                    YSSharedPreferences.setStringValue('priceType', item['type']);
                    Provider.of<YSPriceTypeNotifier>(context, listen: false).setType(item['type']);
                  },
                  behavior: HitTestBehavior.opaque,
                  child: Padding(
                    padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15)),
                    child: Row(
                      children: [
                        Expanded(child: RichText(
                          text: TextSpan(
                            style: YSColors.contentStyle(context),
                            text: item['title'],
                            children: const [
                              // WidgetSpan(child: SizedBox(
                              //   width: hsp(30),
                              //   child: Row(
                              //     children: [
                              //       Padding(
                              //         padding: EdgeInsets.only(left: hsp(5),right: hsp(5)),
                              //         child: Image.asset(YSColors.imageStyle(context, '数据折线上升4备份'),height: hsp(10),width: hsp(10),),
                              //       ),
                              //       Image.asset(YSColors.imageStyle(context, '数据折线上升4'),height: hsp(10),width: hsp(10),),
                              //     ],
                              //   ),
                              // ),alignment: PlaceholderAlignment.middle)
                            ]
                          ),
                        )),
                        if(isChoose)Icon(Icons.check_circle,size: hsp(20),color: Colors.black,)
                      ],
                    ),
                  ),
                );
              },
              separatorBuilder: (context,index){
                return Divider(height: hsp(1),color: YSColors.lineColor(context),);
              },
              itemCount: _list.length,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
            ),
          );
        }
      ),
    );
  }
}

