Kkatre
- Mar 27, 2020
- Joined Jul 29, 2019
- Edited
Merhaba,
Dismiss ile sarmaladığım card veya listtile’ı linkte bulunan ekran görüntüsündeki gibi başka bir card veya container içine alınca, dismiss özellikli card’ı sürüklediğim zaman onu sarmalayan bir üst card’ın dışına çıkıyor. Yani dismiss her türlü ekranın sağ ve sol sınırına ulaşıp kayboluyor. Ekran görüntüsündeki beyaz card alanının dışına çıkmasını istemiyorum.Merhaba, @Subfly, @neuraminidase7 cevaplarınız için teşekkürler.
Bende soruyu sorduğum gün araştırmaya devam ederken constructor yoluyla olabileceğini öğrenip sorunumu halletmiştim. Hatta proje büyüdükçe, sınıflar çoğaldıkça widget tree’de constructor karmaşası yaşanıp işin içinden çıkılamayacağı için asıl olması gereken yöntemin de @neuraminidase7′ın önerdiği state management yöntemlerinden birini uygulamak gerektiğini öğrendim. İş yoğunluğum nedeniyle foruma geri dönüp yöntemler ile ilgili cevap yazmaya vakit bulamamıştım maalesef.
Hocam öncelikle şunda hem fikir olalım.
Mesele true/false meselesi değil.Bakın üsteki iki kod örneğinden body kısmında yeni sınıf kullandığım kod bloğu ile hata alıyorum. İkinci paylaştığım kod bloğunda sınıf içinden ayrılmadığım yapıda sorun yok.
Şunu anlamaya çalışıyorum. Sınıf içinde sınıf kullanırken önceki sınıfta tanımlı sabit ekranda değerleri oluşmuş appbar, bottomappbar vb. nesneleri değiştirmek için değer gönderme yöntemi nedir? Benim uyguladığım yöntem doğru mu?
Nasıl ulaşacağım ilk sınıfa?Yöntem : _HomePageState().barDegisim()
Ayrıca son gönderdiğiniz yapıyı denedim.
Sonuç :I/flutter ( 4922): The setter 'bottomNavDurum=' was called on null. I/flutter ( 4922): Receiver: null I/flutter ( 4922): Tried calling: bottomNavDurum=false
- Edited
Hocam daha net anlatmak için iki farklı kod paylaşayım.
Bir sınıfın scaffold gövdesine farklı bir sınıf atayıp ilerleyince appbar veya bottomappbar gibi nesneleri güncelleyemiyorum. Daha doğrusu yöntemi bilmiyorum.
Örnek ;
import 'package:flutter/material.dart'; class HomePage extends StatefulWidget { _HomePageState createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { bool bottomNavDurum = true; @override Widget build(BuildContext context) { debugPrint(bottomNavDurum.toString()); return Scaffold( appBar: AppBar( title: Text("Home Page"), backgroundColor: Colors.red, ), body: SecondPageClass(), bottomNavigationBar: bottomNavDurum ? BottomAppBar( child: Container(height: 50, child: Text("Custom Bottom Bar 1")), color: Colors.red) : BottomAppBar( child: Container(height: 50, child: Text("Custom Bottom Bar 2")), color: Colors.yellowAccent)); } barDegisim(){ setState(() { bottomNavDurum = false; }); } } class SecondPageClass extends StatefulWidget { @override _SecondPageClassState createState() => _SecondPageClassState(); } class _SecondPageClassState extends State<SecondPageClass> { @override Widget build(BuildContext context) { return Center( child: Container( child: RaisedButton( child: Text("Button"), color: Colors.orange, onPressed: () { _HomePageState().barDegisim(); }), ), ); } }
Fakat ilk sınıfın scaffold gövdesine yine aynı sınıftan devam edersem appbar, bottomappbar vb. nesneleri güncelleyebiliyorum.
Örnek,
import 'package:flutter/material.dart'; class HomePage extends StatefulWidget { _HomePageState createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { bool bottomNavDurum = true; @override Widget build(BuildContext context) { debugPrint(bottomNavDurum.toString()); return Scaffold( appBar: AppBar( title: Text("Home Page"), backgroundColor: Colors.red, ), body: secondPageMetod(), bottomNavigationBar: bottomNavDurum ? BottomAppBar( child: Container(height: 50, child: Text("Custom Bottom Bar 1")), color: Colors.red) : BottomAppBar( child: Container(height: 50, child: Text("Custom Bottom Bar 2")), color: Colors.yellowAccent)); } secondPageMetod(){ return Center( child: Container( child: RaisedButton( child: Text("Button"), color: Colors.orange, onPressed: () { barDegisim(); }), ), ); } barDegisim(){ setState(() { bottomNavDurum = false; }); } }
Denedim hocam maalesef sonuç aynı.
İşte nasıl yenileyeceğim sayfayı?
- Edited
onPressed: () { setState(() { HomePage() .createState() .bottomNavDurum = false; }); }
Bunu zaten denemiştim. setState maalesef değiştirmiyor.
- Edited
Merhaba,
Ana stateful sınıfımda scaffold içinde appbar, body ve bottom navigation bar tanımlarım var. Body widget'ına da içinde buton olan ikinci bir stateful sınıf return oluyor. İkinci sınıf ana sınıfın app ve bottomapp barını kullanıyor kısaca. İkinci sınıftaki buton ile uygulamanın aktif bottomapp barını değiştirmek istiyorum.Yazdığım kodlar şu şekilde
import 'package:flutter/material.dart'; class HomePage extends StatefulWidget { _HomePageState createState () => _HomePageState(); } class _HomePageState extends State<HomePage> { bool bottomNavDurum = true; @override Widget build (BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Home Page"), backgroundColor: Colors.red, ), body: SecondPage(), bottomNavigationBar: bottomNavDurum ? BottomAppBar( child: Container( height: 50, child: Text("Custom Bottom Bar 1")), color: Colors.red) : BottomAppBar( child: Container( height: 50, child: Text("Custom Bottom Bar 2")), color: Colors.yellowAccent) ); } class SecondPage extends StatefulWidget { @override _SecondPageState createState () => _SecondPageState(); } class _SecondPageState extends State<SecondPage> { @override Widget build (BuildContext context) { return Center( child: Container( child: RaisedButton( child: Text("Button"), color: Colors.orange, onPressed: () { HomePage() .createState() .bottomNavDurum = false; }), ), ); } }
Ana sınıftaki bottomappbar'ın durumunu kontrol ettiğim değişkene değeri gönderiyorum fakat setState çalıştırabileceğim bir yapı kuramadım.