|
|
@ -1,6 +1,9 @@
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:audioplayers/audioplayers.dart';
|
|
|
|
import 'package:audioplayers/audioplayers.dart';
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
|
|
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
@ -13,10 +16,11 @@ import 'package:justmusic/screens/post_screen.dart';
|
|
|
|
import 'package:justmusic/screens/profile_screen.dart';
|
|
|
|
import 'package:justmusic/screens/profile_screen.dart';
|
|
|
|
import 'package:justmusic/screens/registration_screen.dart';
|
|
|
|
import 'package:justmusic/screens/registration_screen.dart';
|
|
|
|
import 'package:justmusic/screens/welcome_screen.dart';
|
|
|
|
import 'package:justmusic/screens/welcome_screen.dart';
|
|
|
|
|
|
|
|
import 'package:justmusic/values/constants.dart';
|
|
|
|
import 'package:justmusic/view_model/MusicViewModel.dart';
|
|
|
|
import 'package:justmusic/view_model/MusicViewModel.dart';
|
|
|
|
import 'package:justmusic/view_model/PostViewModel.dart';
|
|
|
|
import 'package:justmusic/view_model/PostViewModel.dart';
|
|
|
|
import 'package:justmusic/view_model/UserViewModel.dart';
|
|
|
|
import 'package:justmusic/view_model/UserViewModel.dart';
|
|
|
|
|
|
|
|
import 'package:justmusic/model/User.dart' as userJustMusic;
|
|
|
|
import 'firebase_options.dart';
|
|
|
|
import 'firebase_options.dart';
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> main() async {
|
|
|
|
Future<void> main() async {
|
|
|
@ -27,8 +31,9 @@ Future<void> main() async {
|
|
|
|
runApp(const MyApp());
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
static FirebaseFirestore db = FirebaseFirestore.instance;
|
|
|
|
static FirebaseFirestore db = FirebaseFirestore.instance;
|
|
|
|
|
|
|
|
|
|
|
|
static UserViewModel userViewModel = UserViewModel();
|
|
|
|
static UserViewModel userViewModel = UserViewModel();
|
|
|
|
static MusicViewModel musicViewModel = MusicViewModel();
|
|
|
|
static MusicViewModel musicViewModel = MusicViewModel();
|
|
|
|
static PostViewModel postViewModel = PostViewModel();
|
|
|
|
static PostViewModel postViewModel = PostViewModel();
|
|
|
@ -36,6 +41,40 @@ class MyApp extends StatelessWidget {
|
|
|
|
|
|
|
|
|
|
|
|
const MyApp({super.key});
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
State<MyApp> createState() => _MyAppState();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
|
|
|
|
|
|
late StreamSubscription<User?> user;
|
|
|
|
|
|
|
|
Stream<userJustMusic.User?> userCurrent = Stream.empty();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
checkSignIn();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<userJustMusic.User?> checkSignIn() async {
|
|
|
|
|
|
|
|
user = FirebaseAuth.instance.authStateChanges().listen((user) async {
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
print('User is currently signed out!');
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
MyApp.userViewModel.userCurrent = (await (MyApp.userViewModel.getUser(user.uid)))!;
|
|
|
|
|
|
|
|
userCurrent = Stream.value(MyApp.userViewModel.userCurrent);
|
|
|
|
|
|
|
|
print('User is signed in!');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
|
|
|
user.cancel();
|
|
|
|
|
|
|
|
super.dispose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
@ -69,7 +108,34 @@ class MyApp extends StatelessWidget {
|
|
|
|
// is not restarted.
|
|
|
|
// is not restarted.
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
home: WellcomeScreen());
|
|
|
|
home: FirebaseAuth.instance.currentUser != null
|
|
|
|
|
|
|
|
? StreamBuilder<userJustMusic.User?>(
|
|
|
|
|
|
|
|
stream: userCurrent,
|
|
|
|
|
|
|
|
initialData: null,
|
|
|
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
|
|
|
|
print("hasdata");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return AnimatedSwitcher(
|
|
|
|
|
|
|
|
duration: Duration(milliseconds: 1000),
|
|
|
|
|
|
|
|
transitionBuilder: (child, animation) {
|
|
|
|
|
|
|
|
return FadeTransition(opacity: animation, child: child);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
child: FeedScreen(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
|
|
|
backgroundColor: bgColor,
|
|
|
|
|
|
|
|
body: Center(
|
|
|
|
|
|
|
|
child: Image(
|
|
|
|
|
|
|
|
image: AssetImage("assets/images/logo.png"),
|
|
|
|
|
|
|
|
width: 130,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
: WellcomeScreen());
|
|
|
|
},
|
|
|
|
},
|
|
|
|
designSize: Size(390, 844),
|
|
|
|
designSize: Size(390, 844),
|
|
|
|
);
|
|
|
|
);
|
|
|
|