Как войти и зарегистрироваться с помощью Rest API, используя флаттер с установлением сеансаAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как войти и зарегистрироваться с помощью Rest API, используя флаттер с установлением сеанса

Сообщение Anonymous »

Я создал форму входа с адресом электронной почты, паролем и кнопкой входа. Я новичок во flutter, dart и Интернете.

Как интегрировать JSON Restfull API для входа и регистрации, используя JSON в качестве объекта.

Также дайте мне знать, как установить сеанс после входа пользователя в систему.

Пожалуйста, дайте мне знать, как пропустить страницу входа, если пользователь уже вошел в систему (с помощью Flutter и Дарт)

Я создал экран входа в систему и экран регистрации, а также экран-заставку

Код: Выделить всё

//Splash Screen UI Code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:interview/myhomepage.dart';
import 'package:interview/signup.dart';

class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => new _SplashScreenState();
}

const TextStyle textStyle = TextStyle(
color: Colors.white,
fontFamily: 'OpenSans',
);

class _SplashScreenState extends State
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation  animation;

@override
void initState() {
super.initState();
controller = AnimationController(
duration: Duration(milliseconds: 2000),
vsync: this,
);

animation = Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {});
});
controller.forward();
}

@override
void dispose() {
super.dispose();
controller.dispose();
}

final background = Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background.jpg'),
fit: BoxFit.cover,
),
),
);
final greenOpacity = Container(
color: Color(0xAA72F1CF),
);

Widget button(String lable, Function onTap) {
return new FadeTransition(
opacity: animation,
child: new SlideTransition(
position: Tween(begin: Offset(0.0, -0.6), end: Offset.zero)
.animate(controller),
child: Material(
color: Color(0xBB00D699),
borderRadius: BorderRadius.circular(30.0),
child: InkWell(
onTap: onTap,
splashColor: Colors.white24,
highlightColor: Colors.white10,
child: Container(
padding: EdgeInsets.symmetric(vertical: 13.0),
child: Center(
child: Text(
lable,
style: textStyle.copyWith(fontSize: 18.0),
),
),
),
),
),
),
);
}

@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

final logo = new ScaleTransition(
scale: animation,
child: Image.asset(
'assets/images/logo.png',
width: 100.0,
height: 100.0,
),
);

final description = new FadeTransition(
opacity: animation,
child: new SlideTransition(
position: Tween(begin: Offset(0.0, -0.8), end: Offset.zero)
.animate(controller),
child: Text(
'The interviewee social network.',
textAlign: TextAlign.center,
style: textStyle.copyWith(fontSize: 24.0),
),
),
);

final separator = new FadeTransition(
opacity: animation,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 20.0,
height: 2.0,
color: Colors.white,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Text(
'OR',
style: textStyle,
),
),
Container(width: 20.0, height: 2.0, color: Colors.white),
],
),
);

final signWith = new FadeTransition(
opacity: animation,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Sign in with',
style: textStyle,
),
GestureDetector(
onTap: () {
print('google');
},
child: Text(
' Google',
style: textStyle.copyWith(
color: Color(0xFFE65100),
fontWeight: FontWeight.bold,
fontSize: 18.0,
),
),
),
Text(' or', style: textStyle),
GestureDetector(
onTap: () {
print('Facebook');
},
child: Text(
' Facebook',
style: textStyle.copyWith(
color: Color(0xFF01579B),
fontWeight: FontWeight.bold,
fontSize: 18.0,
),
),
),
],
),
);

final guestContinue = new FadeTransition(
opacity: animation,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Wana Skip login?',
style: textStyle.copyWith(
color:  Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
)),
GestureDetector(
onTap: () {
print('guest');
},
child: Text(
' Click here!',
style: textStyle.copyWith(
color: Color(0xBB009388),
fontSize: 18.0,
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline),
),
),
],
),
);

return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
background,
greenOpacity,
new SafeArea(
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
logo,
SizedBox(height: 30.0),
description,
SizedBox(height: 60.0),
button('Create an account', () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignupPage()),
);
}),
SizedBox(height: 8.0),
button('Sign In', () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyHomePage()),
);
}),
SizedBox(height: 20.0),
separator,
SizedBox(height: 20.0),
guestContinue,
SizedBox(height: 20.0),
separator,
SizedBox(height: 30.0),
signWith,
],
),
),
),
],
));
}
}

Код: Выделить всё

//Login Page UI code is below:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:interview/signup.dart';

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State  {
@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
body: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Stack(
children: [
Container(
padding: EdgeInsets.fromLTRB(10.0, 110.0, 0.0, 0.0),
child: Text('Hello',
style: TextStyle(
fontSize: 80.0, fontWeight: FontWeight.bold)),
),
Container(
padding: EdgeInsets.fromLTRB(16.0, 175.0, 0.0, 0.0),
child: Text('There',
style: TextStyle(
fontSize: 80.0, fontWeight: FontWeight.bold)),
),
Container(
padding: EdgeInsets.fromLTRB(220.0, 175.0, 0.0, 0.0),
child: Text('.',
style: TextStyle(
fontSize: 80.0,
fontWeight: FontWeight.bold,
color: Colors.teal[800])),
)
],
),
),
Container(
padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
child: Column(
children: [
TextField(
decoration: InputDecoration(
labelText: 'EMAIL',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'PASSWORD',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
obscureText: true,
),
SizedBox(height: 5.0),
Container(
alignment: Alignment(1.0, 0.0),
padding: EdgeInsets.only(top: 15.0, left: 20.0),
child: InkWell(
child: Text(
'Forgot Password?',
style: TextStyle(
color: Colors.teal[800],
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
decoration: TextDecoration.underline),
),
),
),
SizedBox(height: 20.0),
Container(
height: 40.0,
child: Material(
borderRadius: BorderRadius.circular(20.0),
shadowColor: Colors.tealAccent,
color: Colors.teal[500],
elevation: 7.0,
child: GestureDetector(
onTap: () {},
child: Center(
child: Text(
'LOGIN',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily:  'Montserrat'),
),
),
),
),
),
SizedBox(height: 20.0),
],
)),
SizedBox(height: 5.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'New Here ?',
style: TextStyle(fontFamily: 'Montserrat'),
),
SizedBox(width: 5.0),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignupPage()),
);
},
child: Text(
'Register',
style: TextStyle(
color: Colors.teal[800],
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline),
),
)
],
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(width: 5.0),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SignupPage()),
);
},
child: Text(
'Continue as Guest!',
style: TextStyle(
color: Colors.teal[800],
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
fontSize: 16.0,
decoration: TextDecoration.underline),
),
)
],
),
],
),
],
));
}
}

Код: Выделить всё

//Signup Page UI Code is below:
import 'package:flutter/material.dart';

class SignupPage extends StatefulWidget {
@override
_SignupPageState createState() => _SignupPageState();
}

class _SignupPageState extends State  {
@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Stack(
children: [
Container(
padding: EdgeInsets.fromLTRB(15.0, 110.0, 0.0, 0.0),
child: Text(
'Signup',
style: TextStyle(
fontSize: 60.0, fontWeight: FontWeight.bold),
),
),
Container(
padding: EdgeInsets.fromLTRB(190.0, 125.0, 0.0, 0.0),
child: Text(
'.',
style: TextStyle(
fontSize: 60.0,
fontWeight: FontWeight.bold,
color: Colors.teal),
),
)
],
),
),
Container(
padding: EdgeInsets.only(top: 15.0, left: 20.0, right: 20.0),
child: Column(
children: [
TextField(
decoration: InputDecoration(
labelText: 'First Name',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(
labelText: 'Last Name',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(
labelText: 'EMAIL',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(
labelText: 'Mobile Number',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(
labelText: 'PASSWORD ',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color:  Colors.green))),
obscureText: true,
),
SizedBox(height: 10.0),
Container(
height: 40.0,
child: Material(
borderRadius: BorderRadius.circular(20.0),
shadowColor: Colors.greenAccent,
color: Colors.teal,
elevation: 7.0,
child: GestureDetector(
onTap: () {},
child: Center(
child: Text(
'SIGNUP',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
),
)),
SizedBox(height: 30.0),
Container(
height: 40.0,
color: Colors.transparent,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
color: Colors.transparent,
borderRadius: BorderRadius.circular(20.0)),
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Center(
child: Text('Go Back',
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat')),
),
),
),
),
],
)),

]));
}
}


Мне нужна помощь в создании функции, которая может принимать значения, введенные на моей странице регистрации, и завершать регистрацию, а также необходимо добавить ссылку для проверки электронной почты.
Кроме того, мне нужна помощь в создании функции для входа в систему путем вызова RESTFUL API.
При входе должен быть установлен сеанс, и если пользователь возвращается в приложение после входа в систему, он следует направить на домашнюю страницу, пропуская заставку и страницу входа в систему.

Подробнее здесь: https://stackoverflow.com/questions/583 ... ablishment
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»