diff --git a/images/cover-picture.jpg b/images/cover-picture.jpg new file mode 100644 index 0000000..18b5fac Binary files /dev/null and b/images/cover-picture.jpg differ diff --git a/lib/launch_screen.dart b/lib/launch_screen.dart index 9711eeb..82cccbf 100644 --- a/lib/launch_screen.dart +++ b/lib/launch_screen.dart @@ -1,7 +1,10 @@ +import 'dart:async'; + import 'package:firebase_auth/firebase_auth.dart'; -import 'package:firebase_ui_auth/firebase_ui_auth.dart'; import 'package:flutter/material.dart'; -import 'package:telemednet/user_screen.dart'; +import 'package:telemednet/data_service.dart'; +import 'package:telemednet/primary_button.dart'; +import 'package:telemednet/route_names.dart'; class LaunchScreen extends StatefulWidget { const LaunchScreen({super.key}); @@ -11,6 +14,7 @@ class LaunchScreen extends StatefulWidget { } class _LaunchScreenState extends State { + late Timer _timer; @override void initState() { super.initState(); @@ -19,22 +23,106 @@ class _LaunchScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('TelemedNet'), - ), - body: StreamBuilder( - stream: FirebaseAuth.instance.authStateChanges(), - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator(), - ); - } else if (snapshot.hasData) { - return const UserScreen(); - } else { - return const SignInScreen(); - } - }), + body: Container( + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage('images/cover-picture.jpg'), + fit: BoxFit.cover, + ), + ), + child: Container( + alignment: Alignment.bottomCenter, + child: Padding( + padding: const EdgeInsets.all(18.0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + color: const Color.fromARGB(200, 255, 255, 255), + ), + child: SizedBox( + height: 150, + width: double.infinity, + child: Padding( + padding: const EdgeInsets.all(18.0), + child: Center( + child: Column( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'TeleMedNet', + style: Theme.of(context).textTheme.titleLarge, + ), + StreamBuilder( + stream: + FirebaseAuth.instance.authStateChanges(), + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.waiting) { + return const CircularProgressIndicator(); + } else if (snapshot.hasData) { + _timer = + Timer(const Duration(seconds: 3), () { + try { + DataService.getProfile() + .then((profile) { + if (profile == null) { + // ignore: use_build_context_synchronously + Navigator.of(context) + .pushReplacementNamed( + RouteNames.userProfile); + } else { + // ignore: use_build_context_synchronously + Navigator.of(context) + .pushReplacementNamed( + RouteNames.userHome); + } + }); + } finally {} + _timer.cancel(); + }); + return _buildProceedingWidget(context); + } else { + return _buildSignInSignUpRow(context); + } + }) + ], + )), + ), + )), + ), + ))); + } + + Widget _buildProceedingWidget(BuildContext context) { + return const Column( + children: [ + CircularProgressIndicator(), + SizedBox(height: 10), + Text('Please wait...') + ], ); } + + Widget _buildSignInSignUpRow(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: ElevatedButton( + onPressed: () { + Navigator.of(context).pushNamed(RouteNames.signUp); + }, + child: const Text('Sign Up'))), + const SizedBox(width: 10), + Expanded( + child: PrimaryButton( + onPressed: () { + Navigator.of(context).pushNamed(RouteNames.signIn); + }, + text: 'Sign In', + )), + ]); + } } diff --git a/lib/primary_button.dart b/lib/primary_button.dart new file mode 100644 index 0000000..2791f3a --- /dev/null +++ b/lib/primary_button.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; + +class PrimaryButton extends StatelessWidget { + final String text; + final void Function()? onPressed; + + const PrimaryButton({super.key, required this.text, required this.onPressed}); + + @override + Widget build(BuildContext context) { + return ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.primary), + onPressed: onPressed, + child: Text(text, + style: TextStyle(color: Theme.of(context).colorScheme.onPrimary))); + } +} diff --git a/lib/route_names.dart b/lib/route_names.dart index afa5989..3d8ef74 100644 --- a/lib/route_names.dart +++ b/lib/route_names.dart @@ -1,5 +1,6 @@ class RouteNames { static const String signIn = '/sign-in'; - static const String profile = '/profile'; - static const String userCheck = '/user-check'; -} \ No newline at end of file + static const String userProfile = '/user-profile'; + static const String userHome = '/user-home'; + static const String signUp = '/sign-up'; +} diff --git a/lib/routes.dart b/lib/routes.dart index a7267ba..76d5b8c 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -3,6 +3,7 @@ import 'package:firebase_ui_auth/firebase_ui_auth.dart'; import 'package:flutter/material.dart'; import 'package:telemednet/launch_screen.dart'; import 'package:telemednet/route_names.dart'; +import 'package:telemednet/user_profile_screen.dart'; import 'package:telemednet/user_screen.dart'; final Map routes = { @@ -10,6 +11,7 @@ final Map routes = { RouteNames.signIn: (context) => SignInScreen( providers: [EmailAuthProvider(), PhoneAuthProvider()], ), - RouteNames.profile: (context) => const ProfileScreen(), - RouteNames.userCheck: (context) => const UserScreen(), + RouteNames.signUp: (context) => const RegisterScreen(), + RouteNames.userProfile: (context) => const UserProfileScreen(), + RouteNames.userHome: (context) => const UserScreen(), }; diff --git a/lib/user_profile_screen.dart b/lib/user_profile_screen.dart new file mode 100644 index 0000000..e8a9fdf --- /dev/null +++ b/lib/user_profile_screen.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class UserProfileScreen extends StatelessWidget { + const UserProfileScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('User Profile Screen'), + ), + body: const Center( + child: Text('User Profile Screen'), + ), + ); + } +} diff --git a/lib/user_screen.dart b/lib/user_screen.dart index 8176f18..6c34f71 100644 --- a/lib/user_screen.dart +++ b/lib/user_screen.dart @@ -1,55 +1,17 @@ import 'package:flutter/material.dart'; -import 'package:telemednet/data_service.dart'; -import 'package:telemednet/error_view.dart'; -import 'package:telemednet/telemed_user.dart'; -class UserScreen extends StatefulWidget { +class UserScreen extends StatelessWidget { const UserScreen({super.key}); - @override - State createState() => _UserScreenState(); -} - -class _UserScreenState extends State { - late Future telemedUserFuture; - - @override - void initState() { - super.initState(); - telemedUserFuture = DataService.getProfile(); - } - @override Widget build(BuildContext context) { - return Center( - widthFactor: double.infinity, - heightFactor: double.infinity, - child: FutureBuilder( - future: telemedUserFuture, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator(), - ); - } - - if (snapshot.hasError) { - return ErrorView( - message: "Error while loading profile", - okMessage: "OK", - onPressed: () { - Navigator.of(context).pop(); - }, - ); - } - - if (snapshot.hasData) { - final user = snapshot.data!; - return Container(); - } else { - return Container(); - } - }), + return Scaffold( + appBar: AppBar( + title: const Text('User Screen'), + ), + body: const Center( + child: Text('User Screen'), + ), ); } } diff --git a/pubspec.yaml b/pubspec.yaml index b09fc8a..bdb3bfe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -69,6 +69,7 @@ flutter: # - images/a_dot_ham.jpeg assets: - .env + - images/cover-picture.jpg # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/to/resolution-aware-images diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index ae24d2a..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:telemednet/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}