so i have been using future builder in flutter .i have kept the default as CircularProgressIndicator and it always stays in that only I am trying to make a logs app an added a logs service which deals with creating deleting modifying etc(crud)
class LogsView extends StatefulWidget {
const LogsView({super.key});
@override
State<LogsView> createState() => _LogsViewState();
}
class _LogsViewState extends State<LogsView> {
late final LogsService _logsService;
String get userEmail => AuthService.firebase().currentUser!.email!;
@override
void initState(){
_logsService = LogsService();
super.initState();
}
@override
void dispose(){
_logsService.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(backgroundColor: backgroundColour,
appBar: AppBar(backgroundColor: backgroundColour,
title:const Text("Your logs",
style: TextStyle(color: Colors.white)
),
),
body: FutureBuilder(
future:_logsService.getOrCreateUser(email: userEmail),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.done:
return StreamBuilder(
stream: _logsService.allLogs,
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return const Text('Waiting for all notes...');
default:
return const CircularProgressIndicator();
}
},
);
default:
return const CircularProgressIndicator();
}
},
),
);
}
}
this is the logsview dart file
class LogsService {
Database? _db;
List<Databaselog> _logs = [];
static final LogsService _shared = LogsService._sharedInstance();
LogsService._sharedInstance();
factory LogsService() => _shared;
final _logsStreamController =
StreamController<List<Databaselog>>.broadcast();
Stream<List<Databaselog>> get allLogs => _logsStreamController.stream;
Future<DatabaseUser> getOrCreateUser({required String email}) async {
try {
final user = await getUser(email: email);
debugPrint(user.toString());
return user;
} on CouldnotfindUser {
final createdUser = await createUser(email: email);
debugPrint(createdUser.toString());
return createdUser;
} catch (e) {
debugPrint(e.toString());
rethrow;
}
}
this is logs service file code for getorcreateuser
i was trying to wait for the app to go into the connection. done but it never goes it always is stuck in circularprogressindicator