👨🏫0.3 Переменные bool
import 'package:flutter/material.dart';
class Lesson16 extends StatefulWidget {
const Lesson16({super.key});
@override
State<Lesson16> createState() => _Lesson16State();
}
class _Lesson16State extends State<Lesson16> {
bool isSelected = false;
bool isSelectedOne = false;
bool isSelectedTwo = false;
int number = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [
IconButton(
isSelected: isSelected,
onPressed: () {
setState(() {
isSelected = !isSelected;
});
},
icon: Icon(Icons.favorite_border, size: 40),
selectedIcon: Icon(Icons.favorite, size: 40, color: Colors.red),
),
IconButton(
isSelected: isSelectedOne,
onPressed: () {
setState(() {
isSelectedOne = !isSelectedOne;
});
},
icon: Text('Хирург'),
selectedIcon: Container(
height: 50,
width: 100,
color: Colors.orange,
child: Text('Умножить'),
),
),
IconButton(
isSelected: isSelectedTwo,
onPressed: () {
setState(() {
isSelectedTwo = true;
});
},
icon: Row(
mainAxisSize: .min,
children: [Icon(Icons.shopping_cart), Text('add to cart')],
),
selectedIcon: Row(
children: [
IconButton(onPressed: () {
setState(() {
number -= 1;
});
}, icon: Icon(Icons.remove_circle)),
Text('$number'),
IconButton(onPressed: (){
setState(() {
number += 1;
});
}, icon: Icon(Icons.add_circle))
],
),
),
],
),
);
}
}Last updated