微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何在颤振中使用全选复选框?

如何解决我如何在颤振中使用全选复选框?

我用状态管理创建了两个类,一个类在勾选复选框后显示输出,另一个类用于勾选复选框。如何放置全选复选框?我已经尝试过这个 http://5.9.10.113/65445597/how-to-make-a-button-select-all-flutter-checkboxes 但有一些错误,因为我已经分离了输入和输出类。

输出类:

class AbFour extends StatefulWidget {
  @override
  _AbFourState createState() => _AbFourState();
}

class _AbFourState extends State<AbFour> {
  List<Exercise> exercises = [
    Exercise(
        "« 3 sets 10 repetition »","Dumbbell Swing",'DumbbellSwing','assets/images/dumbbell swing.gif',"Hold a dumbbell in both hands. Bend from the hips to lower the weight between your legs,then push your hips forward to raise it up to shoulder height. Reverse back down to the start.",false),Exercise(
        "« 3 sets 10 repetition »","Dumbbell Side Bend",'SideBend','assets/images/side bend.gif',"Stand tall,holding the dumbbell in one hand. Keeping your chest up,lower the weight and it will hit your obliques. Complete all the reps,then switch hands and repeat.","Dumbbell High Ab Crunch",'HighAbCrunch','assets/images/high ab crunch.gif',"Lie on the floor or a mat on your back,with knees bent. Grasp a lightweight dumbbell in two hands,palms facing out,arms extended straight into the air above your shoulders. Feet should be flat on the ground. Keep a space between your chin and chest.","Dumbbell Crunch",'DumbbellCrunch','assets/images/dumbbell crunch.gif',"Lie flat on the floor with your knees bent,holding the dumbbell to your chest with both hands. Use your upper abs to raise your torso,then lower slowly to the start.","Dumbbell Russian Twist",'DumbbellRussianTwist','assets/images/dumbbell russian twist.gif',"Start at the top of the crunch but with your feet off the ground. Rotate back and forth,keeping your abs braced by holding the kettlebell. A twist to one side then the other counts as one rep.",];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("LIST EXERCISE"),),body: Container(
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,children: [
              SizedBox(
                height: getProportionateScreenHeight(20),Row(
                children: const <Widget>[
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: (20)),child: Text("Name",style: TextStyle(
                          fontSize: 18.0,color: kPrimaryLightColor,)),Spacer(),Padding(
                    padding: EdgeInsets.symmetric(horizontal: (20)),child: Text("5/5",child: Text("Preview",],SizedBox(
                height: getProportionateScreenHeight(10),...exercises
                  .map(
                    (exercise) => ListExercise(
                      exercise: exercise,onChanged: (value) {
                        setState(() {
                          exercise.selected = value;
                        });
                      },)
                  .toList(),

输入类:

class ExerciseAbFour extends StatefulWidget {
  final List<Exercise> exercises;
  ExerciseAbFour(this.exercises);

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

class _ExerciseAbFourState extends State<ExerciseAbFour> {
  int currentPage = 0;
  
  String done = "Abs exercise using dumbbell";
  @override
  Widget build(BuildContext context) {
    var selectedExercises =
        widget.exercises.where((element) => element.selected);

    return Scaffold(
        appBar: AppBar(
            title: Text(
          "DAILY fitness",body: Padding(
          padding:
              EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(10)),child: Container(
              child: Column(children: [
            Expanded(
              flex: 5,child: PageView.builder(
                onPageChanged: (value) {
                  setState(() {
                    currentPage = value;
                  });
                },itemCount: selectedExercises.length,itemBuilder: (context,index) => PageView(
                  children: <Widget>[
                    Column(
                      children: [
                        SizedBox(
                          height: getProportionateScreenHeight(10),Text(
                          "Ready to go!",style: TextStyle(
                            fontSize: 25,color: kPrimaryColor,Text(
                          "Exercise:",style: TextStyle(
                            fontSize: 20,Text(
                          selectedExercises.toList()[index].name,SizedBox(
                          height: getProportionateScreenHeight(10),Container(
                            child: ClipRRect(
                          borderRadius: BorderRadius.circular(10.0),child: Image.asset(
                            selectedExercises.toList()[index].image,width: getProportionateScreenWidth(365),SizedBox(
                          height: getProportionateScreenHeight(15),Text(
                          selectedExercises.toList()[index].rep,Text(
                          selectedExercises.toList()[index].description,textAlign: TextAlign.justify,Expanded(
              flex: 1,child: Padding(
                padding: EdgeInsets.symmetric(
                    horizontal: getProportionateScreenWidth(10)),child: Column(
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,children: List.generate(selectedExercises.toList().length,(index) => buildDot(index: index)),SizedBox(
              height: getProportionateScreenHeight(10),DefaultButton(
              text: "Done",press: () {
                inputData();
                showDialog(
                  context: context,barrierdismissible: false,// user must tap button!
                  builder: (BuildContext context) {
                    return AlertDialog(
                        shape: RoundedRectangleBorder(
                            borderRadius:
                                BorderRadius.all(Radius.circular(16.0))),contentPadding: EdgeInsets.all(0.0),content: Container(
                          width: getProportionateScreenWidth(200),height: getProportionateScreenHeight(240),child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,crossAxisAlignment: CrossAxisAlignment.stretch,mainAxisSize: MainAxisSize.min,children: <Widget>[
                              SizedBox(
                                  height: getProportionateScreenHeight(0.1)),Text(
                                'Congratulation!',style: TextStyle(
                                    fontSize: 26.0,letterSpacing: 1.0,fontWeight: FontWeight.bold,color: Colors.greenAccent[400]),textAlign: TextAlign.center,Divider(
                                color: Colors.grey,Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 1.0,horizontal: 0.0),child: Text(
                                  "Nice you have done it!",style: TextStyle(
                                    fontSize: 20.0,InkWell(
                                onTap: () {
                                  Navigator.pushAndRemoveUntil(
                                      context,MaterialPageRoute(
                                        builder: (context) => HomeScreen(),(route) => false);
                                },child: Container(
                                  padding:
                                      EdgeInsets.only(top: 20.0,bottom: 20.0),decoration: Boxdecoration(
                                    color: kPrimaryColor,borderRadius: BorderRadius.only(
                                        bottomLeft: Radius.circular(16.0),bottomright: Radius.circular(16.0)),child: Text(
                                    "Next",style: TextStyle(
                                      color: Colors.white,fontSize: 18.0,)
                            ],));
                  },);
              },SizedBox(
              height: getProportionateScreenHeight(20),])),));
  }

声明列表的类:

class ListExercise extends StatelessWidget {
  final Exercise exercise;
  final Function onChanged;

  ListExercise({
    Key key,this.exercise,this.onChanged,}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var route = exercise.route;
    return Container(
      child: Column(
        children: [
          const Divider(
            height: 20,thickness: 1,indent: 15,endindent: 15,Row(
            children: [
              Expanded(
                child: CheckBoxListTile(
                  title: Text(exercise.name),secondary: IconButton(
                    icon: SvgPicture.asset("assets/icons/review.svg"),onpressed: () {
                      Navigator.pushNamed(context,'/$route');
                    },selectedTileColor: kPrimaryColor,value: exercise.selected,onChanged: onChanged,controlAffinity: ListTileControlAffinity.leading,);
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?