开发者

UI changes only when I hot reload the app

开发者 https://www.devze.com 2022-12-07 18:13 出处:网络
I\'m trying to get data from bottomsheet to model then I show them in listview. I can see everything works but when I trying to add new data it does not show first and then if I hot reload the app I c

I'm trying to get data from bottomsheet to model then I show them in listview.

I can see everything works but when I trying to add new data it does not show first and then if I hot reload the app I can add data and see it listed but for new data I must hot reload again and again I couldn't find the solution




// ignore: must_be_immutable
class MyHo开发者_如何学JAVAmePage extends ConsumerWidget {
  MyHomePage({super.key, required this.title});

  String title;
  ProductInfos product1 = ProductInfos(//model
      firmAdi: firma.text,
      kalite: kalit.text,
      kalinlik: kalinlik.text,
      en: en.text,
      boy: boy.text,
      adet: adet.text,
      kilo: kilo.text,
      pvc: isChecked);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var size = MediaQuery.of(context).size;
    final productInfoProvider = ref.watch(productProvider);

    return Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: Column(
          children: [
            SizedBox(
                height: size.height * 0.5,
                child: ListView.separated(
                  key: UniqueKey(),
                  separatorBuilder: (context, index) {
                    return const Divider(
                      height: 5,
                      thickness: 2,
                    );
                  },
                  itemCount: productInfoProvider.products.length,
                  itemBuilder: (BuildContext context, int index) {
                    return Container(
                      color: Colors.white,
                      child: ListTile(
                        leading: Text(productInfoProvider
                            .products[index].firmAdi
                            .toString()),
                        subtitle: Text(productInfoProvider
                            .products[index].kalite
                            .toString()),
                      ),
                    );
                  },
                )),
            Center(
              child: SizedBox(
                  height: size.height * 0.2,
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.white,
                        foregroundColor: Colors.black),
                    onPressed: () {
                      showModalBottomSheet(
                          context: context,
                          builder: ((context) {
                            return StatefulBuilder(
                                //bottomSheet de statefulbuilder kullanmazsak state yenilenmiyor
                                builder: (BuildContext context, setState) {
                              return SizedBox(
                                height: size.height * 0.5,
                                child: Padding(
                                  padding: const EdgeInsets.all(10.0),
                                  child: Column(
                                    children: [
                                      Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          solBottomSheet(size, setState),
                                          sagBottomSheet(size, setState),
                                        ],
                                      ),
                                      Align(
                                          alignment: Alignment.bottomCenter,
                                          child: ElevatedButton(
                                            onPressed: (() {
                                              setState(
                                                () {
                                                  ref
                                                      .read(productProvider
                                                          .notifier)
                                                      .addProduct(product1);
                                                },
                                              );
                                            }),
                                            style: ElevatedButton.styleFrom(
                                                backgroundColor:
                                                    const Color(0xff74a6cc)),
                                            child: const Text("ekle"),
                                          )),
                                    ],
                                  ),
                                ),
                              );
                            });
                          }));
                    },
                    child: const Text("BottomSheet"),
                  )),
            ),
          ],
        ));
  }

0

精彩评论

暂无评论...
验证码 换一张
取 消