Musa BAL
1 min readSep 14, 2021

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

),

),

),

);

}

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Musa BAL
Musa BAL

No responses yet

Write a response