• 1404/02/09

ران شدن سوالات :

من این دوره را خریداری کردم و الان مشغول کار با این آموزش شدم 
اما متاسفانه در جایی رسیدم که فقط در حال دریافت اطلاعات که نشون میده دیگه به قسمت سوالات نمیره که من سوالات رو جواب بدم

  • 1404/02/10
  • ساعت 00:33

درود
لطفا کدی که توسعه داده اید را ارسال کنید


  • 1404/02/10
  • ساعت 17:02

این هم سورس صحفه کویز

 import 'dart:convert';

import 'package:flutter/material.dart';

import 'package:http/http.dart' as https;

 

class QuizPage extends StatefulWidget {

  const QuizPage({super.key});

 

  @override

  State<QuizPage> createState() => _QuizPageState();

}

 

class _QuizPageState extends State<QuizPage> {

  var questions = [];

  var index = 0;

  int rightAnswerCount = 0;

  int fallAnswerCount = 0;

  var response;

 

  Future<List<dynamic>> fechdata() async {

    var result = await https.get(Uri.parse('http://patakhte.ir/data.json'));

    questions = jsonDecode(result.body)['result'];

    return questions;

  }

 

  void initState() {

    response = fechdata();

    super.initState();

  }

 

  validata(i) {

    if (questions[index]['answerIndex'] == i) {

      setState(() {

        rightAnswerCount++;

      });

    } else {

      setState(() {

        fallAnswerCount++;

      });

    }

    if (index < questions.length - 1) {

      setState(() {

        index++;

      });

    } else {

      Navigator.pushNamed(

        context,

        'Result',

        arguments: {

          'right': rightAnswerCount,

          'fall': fallAnswerCount,

          'total': questions.length,

        },

      );

    }

  }

 

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      extendBodyBehindAppBar: true,

      appBar: AppBar(

        //title: Text(questions[index]['Level']),

        title: FutureBuilder(

          future: response,

          builder: (BuildContext context, AsyncSnapshot snapshot) {

            if (snapshot.hasData) {

              return Text(snapshot.data[index]['Level']);

            } else {

              return Text('... در حال دریافت اطلاعات');

            }

          },

        ),

        backgroundColor: Colors.transparent,

        foregroundColor: Colors.black,

        centerTitle: true,

      ),

      body: FutureBuilder(

        future: response,

        builder: (BuildContext context, AsyncSnapshot snapshot) {

          if (snapshot.hasData) {

            return Column(

              children: [

                Container(

                  width: double.infinity,

                  height: 350.0,

                  color: Colors.yellow,

                  child: Center(

                    child: Text(

                      questions[index]['questions'],

                      style: TextStyle(

                        fontSize: 25,

                        fontWeight: FontWeight.bold,

                      ),

                    ),

                  ),

                ),

                Expanded(

                  child: Container(

                    width: double.infinity,

                    height: 300,

                    color: Colors.black,

                    child: Column(

                      children: [

                        SizedBox(height: 100),

                        Row(

                          crossAxisAlignment: CrossAxisAlignment.start,

                          mainAxisAlignment: MainAxisAlignment.center,

                          children: [

                            SizedBox(

                              width: 150,

                              height: 50,

                              child: ElevatedButton(

                                style: ButtonStyle(

                                  backgroundColor: WidgetStatePropertyAll(

                                    Color.fromARGB(81, 25, 29, 255),

                                  ),

                                ),

                                onPressed: () {

                                  validata(0);

                                },

                                child: Text(questions[index]['Options'][0]),

                              ),

                            ),

                            SizedBox(width: 40),

                            SizedBox(

                              width: 150,

                              height: 50,

                              child: ElevatedButton(

                                style: ButtonStyle(

                                  backgroundColor: WidgetStatePropertyAll(

                                    Color.fromARGB(81, 25, 29, 255),

                                  ),

                                ),

                                onPressed: () {

                                  validata(1);

                                },

                                child: Text(questions[index]['Options'][1]),

                              ),

                            ),

                          ],

                        ),

                        SizedBox(height: 20),

                        Row(

                          crossAxisAlignment: CrossAxisAlignment.start,

                          mainAxisAlignment: MainAxisAlignment.center,

                          children: [

                            SizedBox(

                              width: 150,

                              height: 50,

                              child: ElevatedButton(

                                style: ButtonStyle(

                                  backgroundColor: WidgetStatePropertyAll(

                                    Color.fromARGB(81, 25, 29, 255),

                                  ),

                                ),

                                onPressed: () {

                                  validata(2);

                                },

                                child: Text(questions[index]['Options'][2]),

                              ),

                            ),

                            SizedBox(width: 40),

                            SizedBox(

                              width: 150,

                              height: 50,

                              child: ElevatedButton(

                                style: ButtonStyle(

                                  backgroundColor: WidgetStatePropertyAll(

                                    Color.fromARGB(81, 25, 29, 255),

                                  ),

                                ),

                                onPressed: () {

                                  validata(3);

                                },

                                child: Text(questions[index]['Options'][3]),

                              ),

                            ),

                          ],

                        ),

                      ],

                    ),

                  ),

                ),

              ],

            );

          } else {

            return Center(child: Image.asset('assets/lod.gif'));

          }

        },

      ),

    );

  }

}

 

 


  • 1404/02/13
  • ساعت 01:59

لطفا کد مربوطه را به آیدی تلگرام بنده ارسال کنید
@abolfazldeveloprr


logo-enamadlogo-samandehi