FLUTTER EKRAN YERLEŞİMİ-TERNARY OPERATOR
import ‘package:flutter/material.dart’;
void main() {
runApp(Deneme());
}
class Deneme extends StatefulWidget {
@override
_DenemeState createState() => _DenemeState();
}
class _DenemeState extends State<Deneme> {
String? seciliButon; // değişken tanımlaması yapıldı. ? null olabilir.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar( // home : Scaffold içine AppBar
backgroundColor: Colors.grey[400],
centerTitle: true,
title: Text(
“Flutter ekran denemeleri”,
style: TextStyle(color: Colors.blueGrey[900]),
),
),
body: Center( // Scaffold body içine Row içine children[] içine iki tane container içine 2 tane flatbutton
child: Row(
mainAxisAlignment: MainAxisAlignment.center, // Row un iç elemanları yatay düzlemde ortalandı
children: [
FlatButton(
onPressed: () { // FlatButton onPressed olayına SetState ekledik
setState(() {
seciliButon = “SOL”; //setState içinde anonim fonksiyon ile state değiştirdik
});
print(seciliButon);
},
child: Container(
child: Text(seciliButon == “SOL” ? “Aktif Buton” : “Pasif Buton”), // text yazı değişimi
color: seciliButon == “SOL” ? Colors.red : Colors.blue, // ternary operator ile renk değişimi
width: 100,
height: 200,
),
),
FlatButton(
onPressed: () {
setState(() {
seciliButon = “SAĞ”; //setState içinde anonim fonksiyon ile state değiştirdik
});
},
child: Container(
child: Text(seciliButon == “SAĞ” ? “Aktif Buton” : “Pasif Buton”),
color: seciliButon == “SAĞ” ? Colors.red : Colors.blue,
width: 100,
height: 200,
),
)
], // Children [] sonu
),
),
),
);
}
}