database_helper 0.0.2 database_helper: ^0.0.2 copied to clipboard
Simple Database Helper for sqflite
import 'package:flutter/material.dart';
import 'my_db/myDbHelper.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SQFlite Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
// reference to our single class that manages the database
final dbHelper = MyDbHelper.instance;
// homepage layout
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('sqflite'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// ElevatedButton(
// child: Text(
// 'insert',
// style: TextStyle(fontSize: 20),
// ),
// onPressed: _insert,
// ),
ElevatedButton(
child: Text(
'query',
style: TextStyle(fontSize: 20),
),
onPressed: _query,
),
// ElevatedButton(
// child: Text(
// 'update',
// style: TextStyle(fontSize: 20),
// ),
// onPressed: _update,
// ),
// ElevatedButton(
// child: Text(
// 'delete',
// style: TextStyle(fontSize: 20),
// ),
// onPressed: _delete,
// ),
],
),
),
);
}
// Button onPressed methods
// void _insert() async {
// // row to insert
// Map<String, dynamic> row = {
// columnName.columnName: 'Bob',
// columnAge.columnName: 23
// };
// final id = await dbHelper.insert(row);
// print('inserted row id: $id');
// }
//
void _query() async {
final allRows = await dbHelper.queryAllRows("sv");
print('query all rows:');
allRows.forEach(print);
}
//
// void _update() async {
// // row to update
// Map<String, dynamic> row = {
// columnId.columnName: 1,
// columnName.columnName: 'Mary',
// columnAge.columnName: 32
// };
// final rowsAffected = await dbHelper.update(row);
// print('updated $rowsAffected row(s)');
// }
//
// void _delete() async {
// // Assuming that the number of rows is the id for the last row.
// final id = await dbHelper.queryRowCount();
// final rowsDeleted = await dbHelper.delete(id);
// print('deleted $rowsDeleted row(s): row $id');
// }
}