👨‍🏫0.4 Переменные и операторы final project

import 'package:flutter/material.dart';

class Lesson17 extends StatefulWidget {
  const Lesson17({super.key});

  @override
  State<Lesson17> createState() => _Lesson17State();
}

class _Lesson17State extends State<Lesson17> {
  bool isSelected = false;

  int total = 0;

  int cardOne = 0;
  int cardTwo = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 15),
          child: Column(
            spacing: 15,
            crossAxisAlignment: .start,
            children: [
              ListTile(
                title: Row(
                  children: [Image.asset('assets/leaf.png'), Text('Hello')],
                ),
                subtitle: Text('Hi'),
                trailing: IconButton(
                  onPressed: () {},
                  icon: Badge.count(
                    backgroundColor: Colors.green,
                    count: total,
                    child: Icon(Icons.shopping_cart),
                  ),
                ),
              ),
              TextFormField(
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: 'Search',
                  prefixIcon: Icon(Icons.search),
                ),
              ),
              SingleChildScrollView(
                scrollDirection: Axis.horizontal,
                child: Row(
                  children: [
                    ChoiceChip(
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(30),
                      ),
                      selectedColor: Colors.green,
                      showCheckmark: false,
                      label: Text('All'),
                      selected: isSelected,
                      onSelected: (value) {
                        setState(() {
                          isSelected = value;
                        });
                      },
                    ),
                  ],
                ),
              ),
              GridView(
                shrinkWrap: true,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  mainAxisSpacing: 10,
                  crossAxisSpacing: 10,
                  childAspectRatio: 0.6,
                ),
                children: [
                  Card(
                    child: Container(
                      color: Colors.white,
                      child: Column(
                        children: [
                          Container(
                            height: 152,
                            width: double.infinity,
                            margin: EdgeInsets.only(
                              top: 12,
                              right: 12,
                              left: 12,
                              bottom: 10,
                            ),
                            decoration: BoxDecoration(
                              color: Color(0xFFF9F9F9),
                              image: DecorationImage(
                                image: AssetImage('assets/leaf.png'),
                              ),
                            ),
                            alignment: Alignment.topRight,
                            child: IconButton(
                              onPressed: () {},
                              icon: Icon(Icons.favorite_border),
                            ),
                          ),
                          Container(
                            height: 40,
                            width: double.infinity,
                            //margin: ,
                            decoration: BoxDecoration(
                              border: Border.all(color: Colors.red)
                            ),
                            child: Row(
                              mainAxisAlignment: .center,
                              children: [
                                IconButton(onPressed: (){
                                  setState(() {
                                    cardOne -=1;
                                    total -=1;
                                  });
                                }, icon: Icon(Icons.remove)),
                                Text('$cardOne'),
                                IconButton(onPressed: (){
                                  setState(() {
                                    cardOne +=1;
                                    total +=1;
                                  });
                                }, icon: Icon(Icons.add)),
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  ),

                  Card(
                    child: Container(
                      color: Colors.white,
                      child: Column(
                        children: [
                          Container(
                            height: 152,
                            width: double.infinity,
                            margin: EdgeInsets.only(
                              top: 12,
                              right: 12,
                              left: 12,
                              bottom: 10,
                            ),
                            decoration: BoxDecoration(
                              color: Color(0xFFF9F9F9),
                              image: DecorationImage(
                                image: AssetImage('assets/leaf.png'),
                              ),
                            ),
                            alignment: Alignment.topRight,
                            child: IconButton(
                              onPressed: () {},
                              icon: Icon(Icons.favorite_border),
                            ),
                          ),
                          Container(
                            height: 40,
                            width: double.infinity,
                            //margin: ,
                            decoration: BoxDecoration(
                                border: Border.all(color: Colors.red)
                            ),
                            child: Row(
                              mainAxisAlignment: .center,
                              children: [
                                IconButton(onPressed: (){
                                  setState(() {
                                    cardTwo -=1;
                                    total -=1;
                                  });
                                }, icon: Icon(Icons.remove)),
                                Text('$cardTwo'),
                                IconButton(onPressed: (){
                                  setState(() {
                                    cardTwo +=1;
                                    total +=1;
                                  });
                                }, icon: Icon(Icons.add)),
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Last updated