This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() async{ | |
WidgetsFlutterBinding.ensureInitialized(); | |
final studentDatabase = await $FloorStudentDatabase | |
.databaseBuilder('student.db') | |
.build(); | |
final studentDao = studentDatabase.studentDao; | |
runApp(MyApp(studentDao)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:floor/floor.dart'; | |
@entity | |
class Student { | |
@PrimaryKey(autoGenerate: true) | |
final int id; | |
final String name; | |
final String school; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Column( | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Form( | |
key: formKey, | |
child: Column( | |
children: <Widget>[ | |
TextFormField( | |
decoration: InputDecoration( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StreamBuilder<List<Student>>( | |
stream: studentDao.findAllStudentsAsStream(), | |
builder: (_, snapshot) { | |
if (!snapshot.hasData) return Container(); | |
final students = snapshot.data; | |
print(snapshot.data); | |
return ListView.builder( | |
itemCount: students.length, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return ListTile( | |
title: Text(students[index].name), | |
subtitle: Text(students[index].school), | |
onLongPress: (){ | |
int id = students[index].id; | |
var patient = Student(id: id); | |
print(students[index].name); | |
studentDao.deleteStudent(patient); | |
}, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class Blog{ | |
int id; | |
String title; | |
String body; | |
Blog({this.id, this.title,this.body}); | |
Blog.fromJson(Map json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:http/http.dart' as http; | |
const baseUrl = "https://jsonplaceholder.typicode.com"; | |
class API { | |
static Future getPosts() { | |
var url = baseUrl + "/posts"; | |
return http.get(url); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:parsing_data/model/blog.dart'; | |
import 'package:parsing_data/services/api.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:parsing_data/screen/detail.dart'; | |
class HomeScreen extends StatefulWidget { | |
@override | |
_HomeScreenState createState() => _HomeScreenState(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class DetailScreen extends StatelessWidget { | |
String title; | |
String body; | |
DetailScreen(this.title,this.body); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( |