Skip to content

How to listen updated data from db and return to Ui using stream and getx #657

Answered by pratamatama
neeluagrawal04 asked this question in Q&A
Discussion options

You must be logged in to vote

I assume you have database already set up. You could do something like this...

main.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yourapp/app/app.dart';
import 'package:yourapp/app/services/database_service.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Get.putAsync(() => DatabaseService().init());

  runApp(const App());
}

database_service.dart

import 'package:get/get.dart';
import 'package:yourapp/app/data/database.dart';

class DatabaseService extends GetxService {
  static DatabaseService get instance => Get.find();

  late AppDatabase db;

  Future<DatabaseService> init() async {
    db = await $FloorApp…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dkaera
Comment options

Answer selected by dkaera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants