flutter 我找不到这样的方法,或尝试调用[](“id”)

xqnpmsa8  于 2022-12-24  发布在  Flutter
关注(0)|答案(1)|浏览(103)
ListTile(
  leading: Icon(Icons.person),
  title: const Text('Profilim'),
  onTap: () async {
    print("aaaaaaa");
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => profile(gelenid : widget.gelenid)),
    );
  },
),

当我按下此按钮时,我会得到nosuchmethoderror,并且我在profile.dart中有此代码

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:personal_planner/update.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';

class profile extends StatefulWidget {
  const profile({this.gelenid});
  final gelenid;

  @override
  State<profile> createState() => _profileState();
}
class _profileState extends State<profile> {



  var satir;
  dbGoster() async {
    Directory klasor = await getApplicationDocumentsDirectory();
    String veritabyolu = join(klasor.path, "personal.sqlite");
    Database db = await openDatabase(veritabyolu);
    if (await databaseExists(veritabyolu)){
      print("Var");

      List<Map<String,dynamic>> maps=await db.rawQuery("SELECT * FROM personals WHERE id = ?" ,[widget.gelenid.toString()]);
      List.generate(maps.length, (index) {
        satir=maps[index];
      });}  else {
      print("Veri tabanı yok");
    };
  }
  @override
  Widget build(BuildContext context) {
    dbGoster();

    return Scaffold(
        appBar: AppBar(
          title: Text("Profilim"),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("ID=>"+satir["id"].toString()),
              Text("TC Kimlik=>"+satir["tc"].toString()),
              Text("İsim=>"+satir["isim"]),
              Text("Soyisim=>"+satir["soyisim"]),
              Text("Sifre=>"+satir["sifre"]),
              Text("Medeni=>"+satir["medeni"].toString() ),
              Text("İlgi Alanları=>"+satir["ilgialan"].toString()),
              Text("Ehliyet=>"+satir["ehliyet"].toString()),
              ElevatedButton(onPressed: (){
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => update(gelenid : widget.gelenid)),
                );
              }, child: Text("Güncellemek için bas!")),

            ],
          ),
        ),
    );
  }
}

我尝试了所有可能的方法但都没能修好。
我认为必须先执行sql查询,但我尝试了initstate等。
我尝试在文本小部件的children中使用if else语句,但没有帮助
除了这个-〉当我按下按钮,我得到了nosuchmethoderror,但如果我这样做hotreload页面出现在我的手机上

dxxyhpgq

dxxyhpgq1#

将dbGoster方法调用移至initState方法,以便在build方法之前调用该方法。使用FutureBuilder小部件基于dbGoster方法的结果构建UI。当dbGoster方法中的数据可用时,FutureBuilder小部件将自动重新构建UI

相关问题