01. Переменные часть 2
Last updated
Last updated
Видео урок
Исходный код
// Some code
import 'package:flutter/material.dart';
class Lesson02 extends StatefulWidget {
const Lesson02({super.key});
@override
State<Lesson02> createState() => _Lesson02State();
}
class _Lesson02State extends State<Lesson02> {
String title = '';
int number = 0;
double counter = 0;
bool isAdult = true;
var textVar = const Text('Hello');
var name = 'Baias';
var age = 45;
dynamic textDynamic = const Text('Hello');
dynamic nameDynamic = 'Baias';
dynamic ageDynamic = 45;
Widget text = const Text('Hello');
Icon icon = const Icon(Icons.add);
bool isLike = false;
bool isChangeContainer = false;
// TODO : =, -, +, *, /, !
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: title.isEmpty ? const Center(child: Text('No data'),): Column(
children: [
Text(
'${title.length}',
style: const TextStyle(fontSize: 30),
),
Text(
'${title.isEmpty}',
style: const TextStyle(fontSize: 30),
),
Text(
'${title.isNotEmpty}',
style: const TextStyle(fontSize: 30),
),
Text(
'${title.runtimeType}',
style: const TextStyle(fontSize: 30),
),
Text(
title,
style: const TextStyle(fontSize: 30),
),
Row(
children: [
ElevatedButton(
onPressed: () {
setState(() {
title = title.toUpperCase();
});
},
child: const Text('Upper case')),
ElevatedButton(
onPressed: () {
setState(() {
title = title.toLowerCase();
});
},
child: const Text('Lower case')),
],
),
const SizedBox(
height: 20,
),
Text(
'$number',
style: const TextStyle(fontSize: 30),
),
Row(
children: [
ElevatedButton(
onPressed: () {
setState(() {
number = number.toString().length;
});
},
child: const Text('+')),
ElevatedButton(
onPressed: () {
setState(() {
number--;
});
},
child: const Text('-')),
],
),
Text(
'${textVar.runtimeType}',
style: const TextStyle(fontSize: 30),
),
const SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(title),
Text('$name, $age'),
Text('$nameDynamic')
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
setState(() {
title = 'Hello';
});
},
child: const Text('title')),
ElevatedButton(
onPressed: () {
setState(() {
name = 'Bakjshdkj';
age = 67;
});
},
child: const Text('name')),
ElevatedButton(
onPressed: () {
setState(() {
nameDynamic = true;
});
},
child: const Text('Dynamic'))
],
),
const SizedBox(
height: 30,
),
IconButton(
onPressed: () {
setState(() {
isLike = !isLike;
});
},
icon: isLike
? const Icon(
Icons.favorite,
color: Colors.red,
)
: const Icon(Icons.favorite_border),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: isChangeContainer ? 100 : 150,
width: isChangeContainer ? 100 : 150,
color: isChangeContainer ? Colors.red : Colors.blue,
),
TextButton(onPressed: (){
setState(() {
isChangeContainer = !isChangeContainer;
});
}, child: const Text('change container'))
],
)
],
),
),
);
}
}