Home > Blockchain >  Im getting nosuchmethoderror tried calling []("id")
Im getting nosuchmethoderror tried calling []("id")

Time:12-23

ListTile(
  leading: Icon(Icons.person),
  title: const Text('Profilim'),
  onTap: () async {
    print("aaaaaaa");
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => profile(gelenid : widget.gelenid)),
    );
  },
),

When I press this button im gettin nosuchmethoderror and I have this code in 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!")),

            ],
          ),
        ),
    );
  }
}

I tried every possible what I know and found but I couldn't fix.

I think the sql query must be do first but I tried initstate etc.

I tried if else statement in children for text widget but it couldn't help

Except this-> When I press button I got nosuchmethoderror but if I do hotreload page comes on my phone

CodePudding user response:

Move the dbGoster method call to the initState method so that it is called before the build method. Use a FutureBuilder widget to build the UI based on the result of the dbGoster method. The FutureBuilder widget will automatically rebuild the UI when the data from the dbGoster method becomes available

  • Related