import 'package:betting/view/mobile/test_controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';

class Test extends GetWidget<TestControler>{
  final controller = Get.put(TestControler());
  @override
  Widget build(BuildContext context) {
    return
      Column(
        children: [
          Obx(() =>  ElevatedButton(
              style: ElevatedButton.styleFrom(
                  backgroundColor:    controller.ischeckall.value ==true ? Colors.green : Colors.red
              ),
              onPressed: (){
                controller.ischeckall.value =! controller.ischeckall.value;
                if( controller.ischeckall.value== true){
                  for(int i = 0; i< controller.ischecklist.length; i++){
                    controller.ischecklist[i] = true;
                    controller.indexx.value = controller.ischecklist.length;
                  }
                  print(controller.ischecklist);
                }else{
                  for(int i = 0; i< controller.ischecklist.length; i++){
                    controller.ischecklist[i] = false;
                    controller.indexx.value = 0;
                  }
                }
              },
              child: Text('text'))),
          Obx(() => ListView.builder(
            shrinkWrap: true,
            itemCount: controller.list.length,
            itemBuilder: (context, index) {
              return Row(
                children: [
                Obx(() =>   ElevatedButton(
                    style: ElevatedButton.styleFrom(
                        backgroundColor: controller.ischecklist[index] == false ? Colors.red:  Colors.green
                    ),
                    onPressed: (){
                      controller.ischecklist[index] =! controller.ischecklist[index];


                        if(controller.ischecklist[index] == true){
                           controller.indexx.value ++;
                           print( controller.indexx.value);
                      }

                      if(controller.indexx.value  == controller.ischecklist.length){
                        controller.ischeckall.value = true;
                      }

                      if( controller.ischeckall.value == true){
                          if(controller.ischecklist[index] == false){
                            controller.indexx.value --;
                            print( controller.indexx.value);
                            controller.ischeckall.value = false;
                          }
                      }else{
                        if(controller.ischecklist[index] == false){
                          controller.indexx.value --;
                          print( controller.indexx.value);
                        }
                      }


                    },
                    child: Text('list ${controller.list[index]}'))),
                  Text('${controller.list[index]}')
                ],
              );

            },))
        ],
      );
    
  }

}