Skip to content

Commit

Permalink
Merge pull request #5 from Tuanpluss02/dev
Browse files Browse the repository at this point in the history
fix login delay
  • Loading branch information
Tuanpluss02 authored Apr 12, 2023
2 parents b4e3305 + e4509bd commit cda7e4d
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 62 deletions.
25 changes: 16 additions & 9 deletions lib/components/shorten_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,22 @@ Widget shortenForm(
onPressed: () async {
if (formKey.currentState!.validate()) {
isSubmitting.val = true;
isSuccess.val = await _submitForm(
longUrlController, shortNameController, shortUrl);
recentlyUrls.value.insert(
0,
Urls(
shortUrl: shortUrl.value,
longUrl: longUrlController.text,
shortname: shortNameController.text));
recentlyUrls.refresh();
isSuccess.val = await _submitForm(longUrlController,
shortNameController, shortUrl)
.then((value) {
if (value) {
recentlyUrls.value.insert(
0,
Urls(
shortUrl: shortUrl.value,
longUrl: longUrlController.text,
shortname: shortNameController.text));
recentlyUrls.refresh();
return true;
} else {
return false;
}
});
}
},
isSuccess: isSuccess,
Expand Down
205 changes: 158 additions & 47 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_animated_dialog/flutter_animated_dialog.dart';
import 'package:get/get.dart';
import 'package:url_shortener_flutter/components/recently_widget.dart';
import 'package:url_shortener_flutter/components/shorten_form.dart';
Expand Down Expand Up @@ -91,51 +92,7 @@ class _HomePageState extends State<HomePage> {
controller: _scrollController,
child: Column(
children: [
Container(
margin:
const EdgeInsets.only(top: 10, left: 10, right: 10),
width: size.width,
height: size.height * 0.1,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white.withOpacity(0.5),
width: 2,
),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
const SizedBox(),
Text('Hi, ${widget.user.username}',
style: const TextStyle(
fontSize: 20,
fontFamily: 'RobotReavers',
color: Colors.white,
)),
TextButton(
onPressed: () {
signOut(() {
Navigator.pushReplacementNamed(
context, '/login');
});
},
child: const Text(
'Sign Out',
style: TextStyle(
fontSize: 20,
fontFamily: 'Atomed',
color: Colors.redAccent,
),
))
],
)))),
appBar(size, context),
shortenForm(
size,
formKey,
Expand All @@ -148,8 +105,6 @@ class _HomePageState extends State<HomePage> {
isSubmitting,
isSuccess),
credit(),
// recentlyWidget(size, recentlyUrls, _longUrlController,
// _shortNameController, formFocus)
RecentlyWidget(
size: size,
recentlyUrls: recentlyUrls,
Expand All @@ -165,6 +120,162 @@ class _HomePageState extends State<HomePage> {
));
}

Container appBar(Size size, BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 10, left: 10, right: 10),
width: size.width,
height: size.height * 0.1,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white.withOpacity(0.5),
width: 2,
),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SizedBox(),
Text('Hi, ${widget.user.username}',
style: const TextStyle(
fontSize: 20,
fontFamily: 'RobotReavers',
color: Colors.white,
)),
TextButton(
onPressed: () {
showAnimatedDialog(
barrierColor: Colors.black.withOpacity(0.5),
context: context,
barrierDismissible: true,
builder: (BuildContext dialogContext) {
return Dialog(
elevation: 0,
backgroundColor: Colors.transparent,
child: Container(
height: size.height * 0.4,
width: size.width * 0.2,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.3),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white.withOpacity(0.5),
width: 2,
),
),
child: ClipRRect(
borderRadius:
BorderRadius.circular(20),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 8, sigmaY: 8),
child: Container(
margin: const EdgeInsets.all(10),
child: Column(
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
children: [
const Text(
'Are you sure you want to sign out?',
style: TextStyle(
fontSize: 20.0,
fontFamily: 'Atomed'),
),
Row(
mainAxisAlignment:
MainAxisAlignment.end,
children: [
ElevatedButton(
style: ElevatedButton
.styleFrom(
backgroundColor:
const Color
.fromARGB(
136,
255,
24,
24),
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
20.0),
),
),
onPressed: () {
Navigator.pop(
dialogContext);
signOut(() {
Navigator.pushNamed(
context,
'/login');
});
},
child: const Text(
'Sign Out',
style: TextStyle(
color:
Colors.white),
),
),
const SizedBox(width: 10),
ElevatedButton(
style: ElevatedButton
.styleFrom(
backgroundColor:
const Color
.fromARGB(
135, 0, 0, 0),
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
20.0),
),
),
onPressed: () {
Navigator.pop(
dialogContext);
},
child: const Text(
'Cancel',
style: TextStyle(
color:
Colors.white),
),
),
],
)
],
),
),
))));
},
animationType: DialogTransitionType.size,
curve: Curves.fastOutSlowIn,
duration: const Duration(seconds: 1),
);
},
child: const Text(
'Sign Out',
style: TextStyle(
fontSize: 20,
fontFamily: 'Atomed',
color: Colors.redAccent,
),
))
],
))));
}

Container credit() {
return Container(
margin: const EdgeInsets.all(20),
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ class _LoginPageState extends State<LoginPage> {
trigFail!.fire();
return;
} else {
isSubmitting.val = true;
isSubmitting.val = true; // }
await Auth()
.loginRequest(usernameController.text, passwordController.text)
.then((value) {
if (value != null) {
trigSuccess!.fire();
isSuccess.val = true;
isSubmitting.val = false;
Future.delayed(const Duration(milliseconds: 1500), () {
Future.delayed(const Duration(milliseconds: 500), () {
Navigator
.pushAndRemoveUntil(
context,
Expand Down
3 changes: 0 additions & 3 deletions lib/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class Auth {
debugPrint(e.toString());
return null;
}
if (response.statusCode != 200) return false;
// deleteAllStorage();
await writeStorage('token', response.data['access_token']);
if (response.statusCode != 200) return null;
final token = response.data['access_token'];
await writeStorage('token', token);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/submit_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SubmitButton extends StatelessWidget {
stateTextWithIcon.value = ButtonState.loading;
onPressed!();
Future.delayed(
const Duration(seconds: 1),
const Duration(milliseconds: 1500),
() {
stateTextWithIcon.value =
isSuccess.val ? ButtonState.success : ButtonState.fail;
Expand Down

0 comments on commit cda7e4d

Please sign in to comment.