Arkadaşlar model sınıfım böyle
class Ogrenci {
int _id;
String _isim;
int _aktif;
int get id => _id;
set id(int value) {
_id = value;
}
int get aktif => _aktif;
set aktif(int value) {
_aktif = value;
}
String get isim => _isim;
set isim(String value) {
_isim = value;
}
@override
String toString() {
return 'Ogrenci{_id: $_id, _isim: $_isim, _aktif: $_aktif}';
}
Ogrenci(this._isim, this._aktif);
Ogrenci.withId(this._id,this._isim, this._aktif);
Map<String,dynamic> toMap(){
var map=Map<String,dynamic>();
map["id"]=_id;
map["isim"]=_isim;
map["aktif"]=_aktif;
return map;
}
Ogrenci.fromMap(Map<String,dynamic> map){
this._id=map["id"];
this._isim=map["id"];
this._aktif=map["aktif"];
}
}
Burda main. dart dosyasında çağırıyorum
class MyApp extends StatelessWidget {
Ogrenci ogrenci=Ogrenci("ali", 1);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
Map<String ,dynamic> map=ogrenci.toMap();
print(map.toString());
Ogrenci kopya=Ogrenci.fromMap(map);
print(kopya.toString());
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home:SqfliteIslemleri(),
);
}
Buda çıktısı
I/flutter (28571): {id: null, isim: ali, aktif: 1}
I/flutter (28571): Ogrenci{_id: null, _isim: null, _aktif: 1}
I/flutter (28571): {id: null, isim: ali, aktif: 1}
I/flutter (28571): Ogrenci{_id: null, _isim: null, _aktif: 1}
Gördüğünüz gibi kod iki kere çalışıyor.Nedenini bulamadım