Herkese merhabalar ben Flutter öğrenmeye yeni başladım oradan buradan öğrendiklerimle bir ToDoList benzeri uygulama yapmaya çalışıyorum. Bu uygylamanın verilerini SqfLite kullanarak kaydetmek istiyorum fakat bir türlü başaramadım bana yardımcı olabilir misniz? Kodları aşağıya bırakıyorum.
main.dart:
`import ‘package:flutter/material.dart’;
import ‘package:liste_alfa/alisveris.dart’;
import ‘package:liste_alfa/notlar.dart’;
import ‘package:liste_alfa/yapilacaklar.dart’;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: “Liste”,
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: AnaSayfa(
),
);
}
}
class AnaSayfa extends StatefulWidget {
const AnaSayfa({Key? key}) : super(key: key);
@override
State<AnaSayfa> createState() => _AnaSayfaState();
}
class _AnaSayfaState extends State<AnaSayfa> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(“Liste(BETA)”),
titleSpacing: 00.0,
centerTitle: true,
toolbarHeight: 50.0,
toolbarOpacity: 0.8,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25)
)
),
),
body: Container(child: Padding(
padding: const EdgeInsets.all(35.0),
child: GridView.count(
crossAxisCount: 2,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
children: [
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => AlisVeris()));
},
child: Container(decoration: BoxDecoration(borderRadius: BorderRadius.circular(20),color: Colors.teal,),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.shopping_cart_outlined,size: 40,color: Colors.white,),
Text(“Alışveriş”,style: TextStyle(color: Colors.white,fontSize: 20,),),
],),
),
),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => Yapilacaklar()));
},
child: Container(decoration: BoxDecoration(borderRadius: BorderRadius.circular(20),color: Colors.teal,),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.task_alt,size: 40,color: Colors.white,),
Text(“Yapılacaklar”,style: TextStyle(color: Colors.white,fontSize: 20,),),
],),
),
),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => Notlar()));
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.teal,),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.mode_edit_outline_outlined,size: 40,color: Colors.white,),
Text(“Notlar”,style: TextStyle(color: Colors.white,fontSize: 20,),),
],),
),
),
],
),
),
),
);
}
}
alisveris.dart:
import ‘package:flutter/material.dart’;
class AlisVeris extends StatefulWidget {
const AlisVeris({Key? key}) : super(key: key);
@override
State<AlisVeris> createState() => _AlisVerisState();
}
class _AlisVerisState extends State<AlisVeris> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(“Alışveriş”),
titleSpacing: 00.0,
centerTitle: true,
toolbarHeight: 50.0,
toolbarOpacity: 0.8,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25)
)
),
),
body: AnaEkran(),
);
}
}
class AnaEkran extends StatefulWidget {
@override
State<AnaEkran> createState() => _AnaEkranState();
}
class _AnaEkranState extends State<AnaEkran> {
TextEditingController t1 = TextEditingController();
List alisverisListesi = [];
elemanEkle(){
setState(() {
alisverisListesi.add(t1.text);
t1.clear();
});
}
elemanCikar(){
setState(() {
alisverisListesi.remove(t1.text);
t1.clear();
});
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.teal,
),
child: Column(
children: <Widget>[
Flexible(
child: ListView.builder(
itemCount: alisverisListesi.length,
itemBuilder: (context, indeksNumarasi){
return Padding(
padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
child: Card(
elevation: 10.0,
child: ListTile(
//subtitle: Text(“Alışveriş Malzemeleri”),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(alisverisListesi[indeksNumarasi]),
IconButton(icon: Icon(Icons.delete, color: Colors.red,), onPressed: (){
setState(() {
alisverisListesi.removeAt(indeksNumarasi);
});
})
],
),
subtitle: Text(“Alışveriş Malzemeleri”),
),
),
);
},
),
),
Padding(
padding: const EdgeInsets.all(13.0),
child: TextField(
controller: t1,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.add_circle),
color: Colors.teal,
iconSize: 35,
onPressed: elemanEkle,
),
hintText: “Metin Giriniz…”,
filled: true,
fillColor: Colors.grey.shade300,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(50),
borderSide: BorderSide.none,
),
),
),
),
],
),
);
}
}
yapilacaklar.dart
import ‘package:flutter/material.dart’;
class Yapilacaklar extends StatefulWidget {
const Yapilacaklar({Key? key}) : super(key: key);
@override
State<Yapilacaklar> createState() => _YapilacaklarState();
}
class _YapilacaklarState extends State<Yapilacaklar> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(“Yapılacaklar”),
titleSpacing: 00.0,
centerTitle: true,
toolbarHeight: 50.0,
toolbarOpacity: 0.8,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25)
)
),
),
body: AnaEkran(),
);
}
}
class AnaEkran extends StatefulWidget {
@override
State<AnaEkran> createState() => _AnaEkranState();
}
class _AnaEkranState extends State<AnaEkran> {
TextEditingController t1 = TextEditingController();
List yapilacakListesi = [];
elemanEkle(){
setState(() {
yapilacakListesi.add(t1.text);
t1.clear();
});
}
elemanCikar(){
setState(() {
yapilacakListesi.remove(t1.text);
t1.clear();
});
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.teal,
),
child: Column(
children: <Widget>[
Flexible(
child: ListView.builder(
itemCount: yapilacakListesi.length,
itemBuilder: (context, indeksNumarasi){
return Padding(
padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
child: Card(
elevation: 10.0,
child: ListTile(
//subtitle: Text(“Yapılacaklar”),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(yapilacakListesi[indeksNumarasi]),
IconButton(icon: Icon(Icons.delete, color: Colors.red,), onPressed: (){
setState(() {
yapilacakListesi.removeAt(indeksNumarasi);
});
})
],
),
subtitle: Text(“Yapılacaklar”),
),
),
);
},
),
),
Padding(
padding: const EdgeInsets.all(13.0),
child: TextField(
controller: t1,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.add_circle),
color: Colors.teal,
iconSize: 35,
onPressed: elemanEkle,
),
hintText: “Metin Giriniz…”,
filled: true,
fillColor: Colors.grey.shade300,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(50),
borderSide: BorderSide.none,
),
),
),
),
],
),
);
}
}
notlar.dart:
import ‘package:flutter/material.dart’;
class Notlar extends StatefulWidget {
const Notlar({Key? key}) : super(key: key);
@override
State<Notlar> createState() => _NotlarState();
}
class _NotlarState extends State<Notlar> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(“Yapılacaklar”),
titleSpacing: 00.0,
centerTitle: true,
toolbarHeight: 50.0,
toolbarOpacity: 0.8,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25),
bottomRight: Radius.circular(25)
)
),
),
body: Text(“!!!KAPALI!!!”),
);
}
}
`