🧑🏫01. Переменные часть 1
Видео урок
// Some code
class VaribalesScreen extends StatefulWidget {
const VaribalesScreen({super.key});
@override
State<VaribalesScreen> createState() => _VaribalesScreenState();
}
class _VaribalesScreenState extends State<VaribalesScreen> {
// Примтивные типы данных
String name = 'Nuskayim';
String surname = 'Shumdyraeva';
bool isRain = false;
bool isMarried = true;
int age = 54;
double kg = 76.90;
double km = 54.89;
double width = 300;
double height = 80;
// Flutter типы данных
Color green = Colors.green;
Color red = Colors.red;
IconData favorite = Icons.favorite;
IconData person = Icons.person;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [
Text(name),
Text(name),
Text(name),
Text('Идет дождь - $isRain'),
Text('Замужем - $isMarried'),
Text('возраст $age'),
Container(
height: height,
width: width,
color: green,
),
SizedBox(
height: 10,
),
Container(
height: height,
width: width,
color: green,
),
SizedBox(
height: 10,
),
Container(
height: height,
width: width,
color: green,
),
SizedBox(
height: 10,
),
Container(
height: height,
width: width,
color: green,
),
],
),
);
}
}
class LogicVariables extends StatefulWidget {
const LogicVariables({super.key});
@override
State<LogicVariables> createState() => _LogicVariablesState();
}
class _LogicVariablesState extends State<LogicVariables> {
// = - МЕнять
String name = 'Baiastan';
Color containerColor = Colors.green;
double width = 100;
double height = 100;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [
Text(name),
ElevatedButton(
onPressed: () {
setState(() {
name = 'Hello world';
});
},
child: Text('Изменить имя'),
),
InkWell(
onTap: ( ){
setState(() {
containerColor = Colors.red;
width = 200;
height = 400;
});
},
child: Container(
height: height,
width: width,
color: containerColor,
),
)
],
),
);
}
}Что такое переменные?
2. Типы данных
3. Нулевая безопасность (null safety)
4. Ключевые слова для переменных
5. Использование переменных в Flutter
Last updated