Updated launch screen
This commit is contained in:
parent
8fea8a95e4
commit
f9e124764f
BIN
images/cover-picture.jpg
Normal file
BIN
images/cover-picture.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 MiB |
@ -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<LaunchScreen> {
|
||||
late Timer _timer;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -19,22 +23,106 @@ class _LaunchScreenState extends State<LaunchScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('TelemedNet'),
|
||||
),
|
||||
body: StreamBuilder(
|
||||
stream: FirebaseAuth.instance.authStateChanges(),
|
||||
builder: (BuildContext context, AsyncSnapshot<User?> 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',
|
||||
)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
18
lib/primary_button.dart
Normal file
18
lib/primary_button.dart
Normal file
@ -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)));
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
class RouteNames {
|
||||
static const String signIn = '/sign-in';
|
||||
static const String profile = '/profile';
|
||||
static const String userCheck = '/user-check';
|
||||
}
|
||||
static const String userProfile = '/user-profile';
|
||||
static const String userHome = '/user-home';
|
||||
static const String signUp = '/sign-up';
|
||||
}
|
||||
|
||||
@ -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<String, Widget Function(BuildContext)> routes = {
|
||||
@ -10,6 +11,7 @@ final Map<String, Widget Function(BuildContext)> 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(),
|
||||
};
|
||||
|
||||
17
lib/user_profile_screen.dart
Normal file
17
lib/user_profile_screen.dart
Normal file
@ -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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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<UserScreen> createState() => _UserScreenState();
|
||||
}
|
||||
|
||||
class _UserScreenState extends State<UserScreen> {
|
||||
late Future<TelemedUser?> 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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user