اذهب إلى المحتوى
  • 0

مشكلة في اظهار alert dialog عند النقر على زر flutter

وليد الجمل

السؤال

اقوم ببناء تطبيق flutter .... التطبيق يحوي على  صفحة لدفع المخالفات

اريد اضافة تاكيد للموافقة على الدفع عن طريق ال alert dialog  

استخدم الكود التالي لكن عند الضغط على الزر لا يظهر ال alert dialog

Container(
                decoration: decor,
                child: SingleChildScrollView(
                  child: Container(
                    child: Column(
                      children: [
                        ListTile(
                            subtitle: Text(
                          "Violations:",
                          style: TextStyle(
                              fontSize: 25, fontWeight: FontWeight.bold),
                        )),
                        if (numberOfVilotions == 0)
                          Viol('NO Violation Found', '')
                        else
                          Column(
                            children: [
                              for (int j = 0; j < numberOfVilotions; j++)
                                Container(
                                  padding: EdgeInsets.all(15),
                                  margin: EdgeInsets.all(5),
                                  decoration: BoxDecoration(
                                    color: Colors.white70,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(16.0)),
                                  ),
                                  child: Column(
                                    children: [
                                      Viol(
                                          "Type:", violationData[j]['typeofv']),
                                      Viol("Date:", violationData[j]['datev']),
                                      Viol("Fee:", violationData[j]['fee']),
                                      Viol("Num:", violationData[j]['vionum']),
                                      SizedBox(
                                        height: 10,
                                      ),
                                      FlatButton(
                                        onPressed: () {
                                          print('pay pressed');
                                          child: AlertDialog(
                                                backgroundColor: Colors.red,
                                                shape: borderRadius,
                                                title: Text(
                                                    'Pay The Violation'),
                                                content: Text('Are You Sure?'),
                                                actions: <Widget>[
                                                  FlatButton(
                                                    shape: borderRadius,
                                                    color: Color(0XFF4a707a),
                                                    child: Center(
                                                      child: Text(
                                                        "Yes",
                                                        style: TextStyle(
                                                          color: Colors.white,
                                                        ),
                                                      ),
                                                    ),
                                                    onPressed: () {
                                                      setState(() {
                                                        PayVio(int.parse(
                                                            violationData[j]
                                                            ['vionum']));
                                                      });
                                                    },
                                                  ),
                                                  SizedBox(
                                                    height: 5,
                                                  ),
                                                  FlatButton(
                                                    shape: borderRadius,
                                                    color: Color(0XFF4a707a),
                                                    child: Center(
                                                        child: Text(
                                                          "NO",
                                                          style: TextStyle(
                                                              color: Colors
                                                                  .white),
                                                        )),
                                                    onPressed: () {
                                                      setState(() {
                                                      });
                                                    },
                                                  )
                                                ],
                                              );
                                            }
                                        

 

تم التعديل في بواسطة وليد الجمل
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

إن المكون alert dialog هو عبارة عن widget و الشيفرة لديك لا تقوم بإضافته لشجرة المكونات widgets tree الخاصة بالصفحة، لاحظ أن on press تعمل ك callback function و حتى لو أضافت المكون يتوجب تحديث الحالة وإعادة استدعاء دالة build ليتم إضافة المكون للواجهة.

الحل هو استدعاء show dialog وضمنه alert dialog 

FlatButton(
  onPressed: () {
  print('pay pressed');
  showDialog(
    context: context,
    builder: (BuildContext context) {
    return AlertDialog(
      backgroundColor: Colors.red,
      shape: borderRadius,
      title: Text(
      'Pay The Violation'),
      content: Text('Are You Sure?'),
        actions: <Widget>[
          FlatButton(
            shape: borderRadius,
            color: Color(0XFF4a707a),
          child: Center(
          child: Text(
          "Yes",
          style: TextStyle(
          color: Colors.white,
          ),
          ),
          ),

لاحظ أن المكون showDialog يستقبل سياق البرنامج context ثم يقوم ببناء build ل pop up واجهة التحذير و يظهر ضمنها alert dialog وبالتالي يظهر المكون بشكل صحيح.

أي أن showDialog هو من ضيف alertDialog للصفحة الحالية.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...