0

由于代码如此庞大且超过 1000 行,我无法放置完整代码,我可以放置一些信息代码,在其中调用函数并从服务器获取数据,我想将这些数据显示在 home 的正文中,我已经为 homebody 创建了一个单独的文件并在主页中调用它。但我无法在正文功能中传递服务器数据,谁能帮帮我,我是一个初学者

    class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool isLoggedIn = false;
  String schoolid = "";
  String uid = "";
  String pwd = "";
  NetworkHandler networkHandler = NetworkHandler();
  ProfileModel profileModel = ProfileModel();
  DateTime? backbuttonpressedtime;
  _HomePageState() {
    MySharedPreferences.instance
        .getBooleanValue("loggedin")
        .then((value) => setState(() {
              stringer.isLoggedIn1101 = value;
            }));
    MySharedPreferences.instance
        .getStringValue("schoolcode")
        .then((value) => setState(() {
              stringer.schoolid1101 = value;
            }));
    MySharedPreferences.instance
        .getStringValue("uid")
        .then((value) => setState(() {
              stringer.uid1101 = value;
            }));
    MySharedPreferences.instance
        .getStringValue("password")
        .then((value) => setState(() {
              stringer.pwd1101 = value;
            }));
    MySharedPreferences.instance
        .getStringValue("image")
        .then((value) => setState(() {
              stringer.img1101 = value;
            }));
    Map<String, String> dataprofile = {
      "schoolid": stringer.schoolid1101,
      "studid": stringer.uid1101,
      "password": stringer.pwd1101,
      "image": stringer.img1101,
    };
    usrprofile(dataprofile);

  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
          title: const Text("Home"),
          backgroundColor: Vx.blue900,
          iconTheme: const IconThemeData(color: Colors.white)),
      drawer: MyDrawer(),
      body: 
        child: profile(context),
      ),
    );
  }


  Future<void> usrprofile(Map<String, String> data) async {
    Map<String, String> usrdata = {
      "schoolid": stringer.schoolid1101,
      "studid": stringer.uid1101,
      "password": stringer.pwd1101,
    };
    try {
      var response = await networkHandler
          .post("Api.php?apicall=profile", data)
          .then((value) => value.body);

      Map<String, dynamic> map = jsonDecode(response);

      //   print(map);
      //   return;

      if (map["error"] == true) {
        Fluttertoast.showToast(
            msg: map["message"],
            // msg: "Your Device may facing some Connectivity issue...",
            toastLength: Toast.LENGTH_SHORT,
            gravity: ToastGravity.CENTER,
            timeInSecForIosWeb: 1);
        return;
      } else {
        //   print(map["user"]);

        Fluttertoast.showToast(
            msg: "Wait we are fatching information...",
            toastLength: Toast.LENGTH_SHORT,
            gravity: ToastGravity.CENTER,
            timeInSecForIosWeb: 1);
        
         ProfileModel profileModel = ProfileModel.fromJson(map["user"]);
       
      }
    } catch (e) {
      Fluttertoast.showToast(
          
          msg: e.toString(),
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.CENTER,
          timeInSecForIosWeb: 1);
    }
  }
}

在这里,我想在另一个名为的文件中准备的函数中传递数据

profile(context)

    import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:school_book/utils/strings.dart';

Widget profile(context) => Builder(builder: (context) {
      final Map item;
      Uint8List profile = base64.decode(img1101);
     
      return Column(
        children: <Widget>[
          
       
          Expanded(
            child: Container(
              decoration: const BoxDecoration(
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(30),
                      topRight: Radius.circular(30)),
                  gradient: LinearGradient(
                      begin: Alignment.topRight,
                      end: Alignment.bottomLeft,
                      colors: [Colors.black54, Color.fromRGBO(0, 30, 102, 1)])),
              height: (MediaQuery.of(context).size.height),
              child: Padding(
                padding: const EdgeInsets.fromLTRB(1, 10, 1, 1),
                child: ListView(
                  children: [
                    Card(
                      elevation: 2,
                      margin: const EdgeInsets.fromLTRB(15, 4, 15, 2),
                      color: Colors.transparent,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(15.0),
                      ),
                      clipBehavior: Clip.antiAlias,
                      child: Container(
                        decoration: const BoxDecoration(
                          border: const Border(
                              right: const BorderSide(
                                  color: Colors.green, width: 8)),
                        ),
                        child: Column(
                          children: [
                            const ListTile(
                                // leading: Icon(Icons.arrow_drop_down_circle),
                                title: DecoratedBox(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD2D7E5),
                                  shape: BoxShape.rectangle,
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(8.0))),
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
                                child: Text(" Personal Details",
                                    style: TextStyle(
                                      color: Color(0xFF03050C),
                                    ),
                                    textAlign: TextAlign.center),
                              ),
                            )),
                            const Divider(
                              height: 0,
                              thickness: 2,
                              indent: 1,
                              endIndent: 1,
                              color: Colors.white60,
                            ),
                            Padding(
                              padding: const EdgeInsets.fromLTRB(10, 15, 10, 4),
                              child: Container(
                                height: 60,
                                child: Align(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      //mainAxisSize: MainAxisSize.max,
                                      children: const <Widget>[
                                        Padding(
                                          padding: EdgeInsets.all(8.0),
                                          child: Text(
                                            "Name:",
                                            textAlign: TextAlign.left,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white70),
                                          ),
                                        ),
                                        Padding(
                                          padding: EdgeInsets.all(8.0),
                                          child: Text(
                                            " wants data here",
                                            textDirection: TextDirection.ltr,
                                            textAlign: TextAlign.left,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white70),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                                decoration: BoxDecoration(
                                    borderRadius: const BorderRadius.all(
                                        Radius.circular(20)),
                                    border: Border.all(
                                        width: 1.0, color: Colors.white70)),
                              ),
                            ),
                            Padding(
                              padding: const EdgeInsets.fromLTRB(10, 5, 10, 15),
                              child: Container(
                                height: 60,
                                child: Align(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      //mainAxisSize: MainAxisSize.max,
                                      children: const <Widget>[
                                        Padding(
                                          padding: EdgeInsets.all(8.0),
                                          child: Text(
                                            "Class:",
                                            textAlign: TextAlign.left,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white70),
                                          ),
                                        ),
                                        Padding(
                                          padding: EdgeInsets.all(8.0),
                                          child: Text(
                                            "wants data here",
                                            textDirection: TextDirection.ltr,
                                            textAlign: TextAlign.left,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white70),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                                decoration: BoxDecoration(
                                    borderRadius: const BorderRadius.all(
                                        Radius.circular(20)),
                                    border: Border.all(
                                        width: 1.0, color: Colors.white70)),
                              ),
                            ),
                            Padding(
                              padding: const EdgeInsets.fromLTRB(10, 5, 10, 15),
                              child: Container(
                                height: 60,
                                child: Align(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      //mainAxisSize: MainAxisSize.max,
                                      children: const <Widget>[
                                        Padding(
                                          padding: EdgeInsets.all(8.0),
                                          child: Text(
                                            "Birthday:",
                                            textAlign: TextAlign.left,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white70),
                                          ),
                                        ),
                                        Padding(
                                          padding: EdgeInsets.all(8.0),
                                          child: Text(
                                            "wants data here",
                                            textDirection: TextDirection.ltr,
                                            textAlign: TextAlign.left,
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white70),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                                decoration: BoxDecoration(
                                    borderRadius: const BorderRadius.all(
                                        const Radius.circular(20)),
                                    border: Border.all(
                                        width: 1.0, color: Colors.white70)),
                              ),
                            ),
                           
                               
                               
                           
                          ],
                        ),
                      ),
                    ),
                  
                 
                   
                   
                  ],
                ),
              ),
            ),
          )
        ],
      );
    });
4

0 回答 0