🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / FLUTTER / AlertDialog showDialog vs kullanımı

1-) FLUTTER - AlertDialog showDialog vs kullanımı

 

NOT :

Alertdialog da anlık değişiklik olsun dersen GetX kullan. Setstate o zaman işler

DİĞER NOT : setState() or markNeedsBuild called during build BU HATAYI ALIRSAN
WidgetsBinding.instance.addPostFrameCallback((_){

 

  // Add Your Code here.

 

});

 

1-) ekran görüntüsü

 

 

2-) kod

 

 

showDialog(
    context: context,
    builder: (context) {
      
return AlertDialog(
        title:
null,
        content:
Column(
          mainAxisSize:
MainAxisSize.min,
          children: [
          
ElevatedButton(
              onPressed: () {
                
Navigator.pop(context);
                
Navigator.of(context).push(MaterialPageRoute(
                    builder: (context) =>
AlakartContent(
                      currentModel:
currentModel,
                    )));
              },
              child:
Text("YENİ REZERVASYON OLUŞTUR")),
          
ElevatedButton(
              onPressed: () {
Navigator.pop(context);


              },
              child:
Text("GEÇMİŞ REZERVASYONLARIM"))
        ],),
      );
    });

 

 

3-) DİĞER

 

 

void alertDialog(BuildContext context) {
 showDialog(
    barrierDismissible:
false, // boşluğa tıklasa bile kapatmaz.
    
context: context,
    builder: (contex) {
      
return AlertDialog(
        title:
Text("Çıkmak istediğine emin misin ?"),
        actions: [
          
ElevatedButton(
              onPressed: () {
                
Navigator.pop(context);
              },
              child:
Text("İPTAL")),
          
ElevatedButton(
              onPressed: () {
                
Navigator.pop(context);
                
Navigator.pop(context);
              },
              child:
Text("EVET"))
        ],
      );
    });

}

 

 

 

 

 

 

4-) BU DAHA GÜZEL GİBİ

 

  void teklifVerDialog() {
    showDialog(
      context:
context,
      builder: (context) {
        
return AlertDialog(
          backgroundColor:
Colors.transparent,
          insetPadding:
EdgeInsets.all(10),
          title:
null,
          content:
Material(
            elevation:
5,
            shape:
RoundedRectangleBorder(
                borderRadius:
BorderRadius.all(
                  
Radius.circular(15.0),
                )),
            child:
Container(
              width:
450,
              height:
285,
              child:
Column(
                children: [
                  
Padding(
                    padding:
EdgeInsets.only(left: 10, right: 10, bottom: 10,top: 35),
                    child:
Material(

                      elevation:
5,
                      shape:
RoundedRectangleBorder(
                          borderRadius:
BorderRadius.all(
                            
Radius.circular(15.0),
                          )),
                      child:
TextFormField(
                        style:
TextStyle(fontSize: 17, fontWeight: FontWeight.bold),
                        maxLines:
3,
                        autofocus:
true,
                        decoration:
InputDecoration(
                          icon:
Icon(Icons.topic_outlined),
                          labelText:
"Açıklama...",
                          border:
InputBorder.none,
                          labelStyle:
TextStyle(fontSize: 15),
                          contentPadding:
                          
const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
                        ),
                      ),
                    ),
                  ),
                  
Padding(
                    padding:
EdgeInsets.only(left: 10, right: 10, bottom: 10),
                    child:
Material(
                      elevation:
5,
                      shape:
RoundedRectangleBorder(
                          borderRadius:
BorderRadius.all(
                        
Radius.circular(15.0),
                      )),
                      child:
TextFormField(
                        style:
TextStyle(fontSize: 17, fontWeight: FontWeight.bold),
                        decoration:
InputDecoration(
                          icon:
Icon(Icons.account_balance_wallet_outlined),
                          labelText:
"Fiyat",
                          border:
InputBorder.none,
                          labelStyle:
TextStyle(fontSize: 15),
                          contentPadding:
const EdgeInsets.symmetric(
                              vertical:
5.0, horizontal: 10.0),
                        ),
                        keyboardType:
TextInputType.number,
                        inputFormatters: [
formatter],
                        controller:
txtTeklifButce,
                        onChanged: (
String deger) {
                          
if (deger != null && deger.contains("-")) {
                            
txtTeklifButce.clear();
                          }
                        },
                      ),
                    ),
                  ),

                  
Padding(
                    padding:
EdgeInsets.only(top: 15),
                    child:
Row(
                      mainAxisAlignment:
MainAxisAlignment.spaceBetween,
                      children: [
                        
Padding(
                          padding:
EdgeInsets.only(left: 15),
                          child:
MaterialButton(
                            elevation:
17,
                            onPressed: () {
Navigator.pop(context);
                            },
                            color:
ThemeProvider.themeOf(context)
                                .
data
                                
.bottomAppBarColor,
                            textColor:
ThemeProvider.themeOf(context)
                                .
data
                                
.bottomSheetTheme
                                
.backgroundColor,
                            child:
Row(
                              children: [
                                
Icon(
                                  
Icons.close,
                                  size:
17,
                                  color:
Colors.red,
                                ),
                                
SizedBox(
                                  width:
5,
                                ),
                                
Text(
                                  
"İptal",
                                  style:
TextStyle(fontSize: 13),
                                ),
                              ],
                            ),
                          ),
                        ),
                      
Padding(
                        padding:
EdgeInsets.only(right: 15),
                        child:
MaterialButton(
                          elevation:
17,
                          onPressed: () {

                          },
                          color:
ThemeProvider.themeOf(context)
                              .
data
                              
.bottomAppBarColor,
                          textColor:
ThemeProvider.themeOf(context)
                              .
data
                              
.bottomSheetTheme
                              
.backgroundColor,
                          child:
Row(
                            children: [
                              
Icon(
                                
Icons.offline_pin,
                                size:
17,
                              ),
                              
SizedBox(
                                width:
5,
                              ),
                              
Text(
                                
"Teklifi Gönder",
                                style:
TextStyle(fontSize: 13),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],),
                  )

                ],
              ),
            ),
          ),
        );
      },
    );
  }

 

ekran görüntüsü

 

 

 

 

 

 

 

ALERT DİALOG İÇİNDE GRİDVİEW KULLANIMI

 

EKRAN GÖRÜNTÜSÜ

 

 

class UrunModel {
  
int? id;
  
int? kategoriId;
  
String? urunAd; // AYRAN KOLA DÖNER PİZZA
}

 

 

Widget getAltUrun(){

  
List<UrunModel> listem =[];
  
for(int i=1;i<50;i++){
    
UrunModel model =new UrunModel();
    
model.id=i;
    
model.urunAd="Alt ürün $i";
    
model.kategoriId=i;
    
listem.add(model);
  }


  
var grid = Container(
    height:
500,
    width:
300,
    child:
GridView.builder(
      itemCount:
listem.length,
      
// scrollDirection: Axis.horizontal, // scrool soldan sağa olur
      
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount:
2,
        mainAxisExtent:
85, // yükseklik demek
      
),
      itemBuilder: (
BuildContext contex, int index) {
        
var alturun = listem[index];
        
return Container(
          child:
InkWell(
            onTap: () {
// alt ürün
              
Sabitler.mesajYaz(alturun.urunAd!);
            },
            child:
Card(
              shape:
RoundedRectangleBorder(
                  borderRadius:
BorderRadius.circular(20)),
              child:
Center(
                child:
Container(
                  padding:
EdgeInsets.only(left: 5, right: 5),
                  child:
Text(
                    
alturun.urunAd!,
                    textAlign:
TextAlign.center,
                    style:
                    
TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                  ),
                ),
              ),
            ),
          ),
        );
      },
    ),
  );

  
return grid;
}

showAlertDialog() {

  
Widget cancelButton = TextButton(
    child:
Text("İptal"),
    onPressed:  () {
Navigator.pop(context);},
  );
  
Widget continueButton = TextButton(
    child:
Text("Tamam"),
    onPressed:  () {

      
Navigator.pop(context);
    },
  );

  
AlertDialog alert = AlertDialog(
     title:
Text("Alt ürünler"),
    content: getAltUrun(),
    actions: [
      
cancelButton,
      
continueButton,
    ],
  );

  showDialog(
    context:
context,
    builder: (
BuildContext context) {
      
return alert;
    },
  );
}

 

 

 2024 Nisan 01 Pazartesi
 591