Переменные часть 3
// Some code
class LessonFunction extends StatefulWidget {
const LessonFunction({super.key});
@override
State<LessonFunction> createState() => _LessonFunctionState();
}
class _LessonFunctionState extends State<LessonFunction> {
// String - int - double - bool
String name = 'Baiastan';
int age = 26;
double weight = 76.5;
bool isMarried = true;
// var - dynamic - final - const
// =, +=, -=, \=, *=, +
// ? - ?? -
// variable? - можеть быть пустым
// late - чуть позже дадите значение
// variable! - гарантия что не пустая
// !bool -
String title = '';
TextEditingController nameController = TextEditingController();
TextEditingController aController = TextEditingController();
TextEditingController bController = TextEditingController();
double c = 0;
String? car;
String? city;
String? village;
// bool ? значение : значение
// !isLike = false;
bool isLike = false;
bool isContainer = false;
bool isWidget = false;
bool isBody = false;
bool isObscureText = true;
@override
Widget build(BuildContext context) {
return Scaffold(
body: isBody
? SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Добро пожаловать, $title ',
style: TextStyle(fontSize: 30),
),
TextField(
controller: nameController,
decoration: InputDecoration(border: OutlineInputBorder()),
),
ElevatedButton(
onPressed: () {
setState(() {
title = nameController.text;
});
},
child: Text('Name'),
),
Row(
children: [
Expanded(
child: TextField(
controller: aController,
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
),
SizedBox(
width: 10,
),
Expanded(
child: TextField(
controller: bController,
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
setState(() {
c =
double.tryParse(aController.text)! +
double.tryParse(bController.text)!;
});
},
child: Text('A + B'),
),
Text(
'A+B = $c',
style: TextStyle(fontSize: 30),
),
],
),
IconButton(
onPressed: () {
setState(() {
// =
isLike = !isLike;
});
},
icon: Icon(
isLike ? Icons.favorite : Icons.favorite_border,
size: isLike ? 60 : 30,
color: isLike ? Colors.red : Colors.black,
),
),
InkWell(
onTap: () {
setState(() {
isContainer = !isContainer;
});
},
child: Container(
// bool ? true : false;
// bool ? значение : значение;
height: isContainer ? 200 : 100,
width: isContainer ? 100 : 200,
color: isContainer ? Colors.green : Colors.black,
),
),
InkWell(
onTap: () {
setState(() {
isWidget = !isWidget;
});
},
child: isWidget
? Container(
height: 100,
width: 100,
color: Colors.black,
)
: Icon(
Icons.favorite,
size: 90,
),
),
],
),
),
)
: SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
TextField(
obscureText: isObscureText,
decoration: InputDecoration(
border: OutlineInputBorder(),
suffixIcon: IconButton(
onPressed: () {
setState(() {
isObscureText = !isObscureText;
});
},
icon: Icon(
isObscureText
? Icons.remove_red_eye
: Icons.visibility_off,
),
),
),
),
_text('jshfjk', 'Baiastan')
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
isBody = !isBody;
});
},
),
);
}
Widget _text(String text, String name){
return Text('');
}
}👋 Ребята, простыми словами о том, что сегодня разобрали!
1. Тернарный оператор (? :)
2. Controller (TextEditingController)
Last updated