zotdb_flutter 2.6.2
zotdb_flutter: ^2.6.2 copied to clipboard
ZotDB Flutter lib, which allows to connect the ZotDB server.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:zotdb_flutter/zotdb_flutter.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
//controller isn't required in this example.
final TextEditingController _controller = TextEditingController();
String recievedTxt = "";
///TO Init just call static init() method and pass DB url.
///child() method is used to pass location of something in json, and path can either be used as:-
///zotDB.child("foo/abc") or zotDB.child("foo").child("abc")
late ZotDB zotDB = ZotDB.init("ws://localhost:19195/ssdd");
@override
void initState() {
super.initState();
///let's say we have a JSON like:-
//{
//
// "ssdd": {
// "abc": {
// "xyz": {
// "xyz1": "ayo"
// }
// }
// }
//
// }
/// used to listen to single value.
/// the output should be "ayo"
/// [snap] is a dynamic value which is fetched from the server.
zotDB.child("abc/xyz/xyz1").addSingleValueEventListener((snap) {
setState(() {
recievedTxt = snap.toString();
});
});
/// to update Value in the DB you can use setValue() method
/// now the value should be updated from "ayo" to "hie" in DB as well as in your app.
zotDB.child("abc/xyz/xyz1").setValue("hie");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
children: [
EditableText(
controller: _controller,
focusNode: FocusNode(),
onChanged: (txt) {
zotDB.child("abc/xyz/xyz1").setValue(txt);
},
style: const TextStyle(),
cursorColor: Colors.blue,
backgroundCursorColor: Colors.white),
///this just displays text which is fetched from the server.
Text(recievedTxt),
],
),
)),
);
}
}