Skip to content
Snippets Groups Projects
Commit 5d29e0ff authored by CAYLA Julien's avatar CAYLA Julien
Browse files

Début d'application flutter, avec gestions des comptes (sans le token), + affichage des rooms

parent b5a842f7
No related branches found
No related tags found
No related merge requests found
Showing
with 914 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Flutter View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="FlutterViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutter_auth</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
#import "GeneratedPluginRegistrant.h"
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Login/login_screen.dart';
import 'package:flutter_auth/Screens/Signup/signup_screen.dart';
import 'package:flutter_auth/Screens/Index/components/background.dart';
import 'package:flutter_auth/components/rounded_button.dart';
import 'package:flutter_auth/constants.dart';
import 'package:flutter_svg/svg.dart';
import'package:flutter_auth/Screens/staticvar.dart' as staticvar;
class Profil extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
// This size provide us total height and width of our screen
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Modifier votre profil " + staticvar.username,
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Index/components/background.dart';
import 'package:flutter_auth/Screens/Index/components/body.dart';
import 'package:flutter_auth/Screens/Index/components/Profil.dart';
import 'package:flutter_auth/Screens/Index/components/chat.dart';
class TabBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Background(
child: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(text: "Accueil"),
Tab(text: "Message"),
Tab(text: "Profil"),
],
),
title: Text('Se Déconnecter'),
),
body: TabBarView(
children: [
Body(),
MessagesListView(),
Profil(),
],
),
),
),
);
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
class Background extends StatelessWidget {
final Widget child;
const Background({
Key key,
@required this.child,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
height: size.height,
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
top: 0,
left: 0,
child: Image.asset(
"assets/images/main_top.png",
width: size.width * 0.3,
),
),
Positioned(
bottom: 0,
left: 0,
child: Image.asset(
"assets/images/main_bottom.png",
width: size.width * 0.2,
),
),
child,
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Login/login_screen.dart';
import 'package:flutter_auth/Screens/Signup/signup_screen.dart';
import 'package:flutter_auth/Screens/Index/components/background.dart';
import 'package:flutter_auth/components/rounded_button.dart';
import 'package:flutter_auth/constants.dart';
import 'package:flutter_svg/svg.dart';
import'package:flutter_auth/Screens/staticvar.dart' as staticvar;
class Body extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
// This size provide us total height and width of our screen
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Bienvenue sur la page d'accueil de l'application " + staticvar.username,
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
);
}
}
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_auth/Screens/Model/message.dart';
import 'package:flutter_auth/Screens/Login/components/body.dart' as log;
import'package:flutter_auth/Screens/staticvar.dart' as staticvar;
class MessagesListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Messages>>(
future: _fetchMessages(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Messages> data = snapshot.data;
return _MessagesListView(data);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return CircularProgressIndicator();
},
);
}
Future<List<Messages>> _fetchMessages() async {
final MessagesListAPIUrl = "http://10.0.2.2:3000/rooms";
String token = staticvar.token ;
final response = await http.get(MessagesListAPIUrl,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
});
print(response.statusCode);
if (response.statusCode == 200) {
List jsonResponse = json.decode(response.body);
return jsonResponse.map((data) => new Messages.fromJson(data)).toList();
} else {
throw Exception('Failed to load message from API');
}
}
ListView _MessagesListView(data) {
return ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) => new Column(
children: <Widget>[
new Divider(
height: 10.0,
),
new ListTile(
leading: new CircleAvatar(
foregroundColor: Theme.of(context).primaryColor,
backgroundColor: Colors.grey,
// backgroundImage: new NetworkImage(dummyData[i].avatarUrl),
),
title: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Text(
data[index].author,
style: new TextStyle(fontWeight: FontWeight.bold),
),
new Text(
data[index].date,
style: new TextStyle(color: Colors.grey, fontSize: 14.0),
),
],
),
subtitle: new Container(
padding: const EdgeInsets.only(top: 5.0),
child: new Text(
data[index].message,
style: new TextStyle(color: Colors.grey, fontSize: 15.0),
),
),
)
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Index/components/TabBarDemo.dart';
import 'package:flutter_auth/Screens/Index/components/body.dart';
class IndexScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: TabBarDemo(),
);
}
}
import 'package:http/http.dart' as http;
class ChatModel {
final String name;
final String message;
final String time;
final String avatarUrl;
ChatModel(this.name, this.message, this.time, this.avatarUrl);
factory ChatModel.fromMap(Map<String, dynamic> json) {
return ChatModel(json['name'], json['message'], json['time'], json['avatarUrl']);
}
factory ChatModel.fromJson(Map<String, dynamic> json) {
return ChatModel(json['id'], json['title'], json['imgUrl'], json['quantity']);
}
}
String url = "http://localhost:19080/messages";
Future<List<ChatModel>> fetchFruit() async {
final response = await http.get(url);
}
List<ChatModel> dummyData = [
new ChatModel("Pawan Kumar", "Hey Fluttezer, "
"You are so amazing !",
"15:30",
"http://www.usanetwork.com/sites/usanetwork/files/styles/629x720/public/suits_cast_harvey.jpg?itok=fpTOeeBb"),
];
import 'package:flutter/material.dart';
class Background extends StatelessWidget {
final Widget child;
const Background({
Key key,
@required this.child,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
width: double.infinity,
height: size.height,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
top: 0,
left: 0,
child: Image.asset(
"assets/images/main_top.png",
width: size.width * 0.35,
),
),
Positioned(
bottom: 0,
right: 0,
child: Image.asset(
"assets/images/login_bottom.png",
width: size.width * 0.4,
),
),
child,
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Login/components/background.dart';
import 'package:flutter_auth/Screens/Signup/signup_screen.dart';
import 'package:flutter_auth/Screens/Index/index_screen.dart';
import 'package:flutter_auth/components/already_have_an_account_acheck.dart';
import 'package:flutter_auth/components/rounded_button.dart';
import 'package:flutter_auth/components/rounded_input_field.dart';
import 'package:flutter_auth/components/rounded_password_field.dart';
import 'package:flutter_svg/svg.dart';
import '../../Index/index_screen.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
import 'package:flutter_auth/Screens/Model/user.dart';
import 'package:flutter_auth/Screens/staticvar.dart' as staticvar;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../Welcome/welcome_screen.dart';
import '../../Welcome/welcome_screen.dart';
class Body extends StatelessWidget {
final storage = FlutterSecureStorage();
String username;
String password;
int code = 0;
String popuptext;
String token;
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Login",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: size.height * 0.03),
SizedBox(height: size.height * 0.03),
RoundedInputField(
hintText: "Your username",
onChanged: (value) {
this.username = value;
},
),
RoundedPasswordField(
onChanged: (value) {
this.password = value;
},
),
RoundedButton(
text: "LOGIN",
press: () async {
var jwt = await loguser(this.username, this.password);
if(jwt != null){
staticvar.username = this.username;
storage.write(key:"jwt", value: json.decode(jwt)["token"]);
print(json.decode(jwt)["token"]);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => IndexScreen()
)
);
} else {
this.popuptext = "Ces informations ne permettent pas la connexion";
showDialog(
context: context,
builder: (BuildContext context) => _buildPopupDialogUserAlreadyRegistered(context),
);
}
},
),
SizedBox(height: size.height * 0.03),
AlreadyHaveAnAccountCheck(
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SignUpScreen();
},
),
);
},
),
],
),
),
);
}
connec(){
// connection(this.username, this.password);
loguser(this.username,this.password);
return true;
}
Widget _buildPopupDialogUserAlreadyRegistered(BuildContext context) {
return new AlertDialog(
title: const Text('Alerte'),
content: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(this.popuptext),
],
),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
textColor: Theme.of(context).primaryColor,
child: const Text('Close'),
),
],
);
}
Future<String> loguser(String username, String password) async {
final http.Response response = await http.post(
'http://10.0.2.2:3000/users/login',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'username': username,
'password': password,
}),
);
if (response.statusCode == 200) {
this.code = response.statusCode;
staticvar.token = json.decode(response.body)["token"];
staticvar.body = response.body;
return response.body;
}
// If the server did return a 200 CREATED response,
// then parse the JSON.
return null;
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Login/components/body.dart';
class LoginScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Body(),
);
}
}
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
class Messages {
final String id;
final String author;
final String message;
final String date;
Messages({this.id, this.author, this.message, this.date});
factory Messages.fromJson(Map<String, dynamic> json) {
return Messages(
id: json['_id'],
author: json['author'],
message: json['message'],
date: json['date'],
);
}
}
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter_auth/Screens/Model/user.dart';
class Room {
final String name;
final String description;
final List<User> users ;
final User createdby;
Room({this.name, this.description, this.users, this.createdby});
factory Room.fromJson(Map<String, dynamic> json) {
return Room(
name: json['name'],
description: json['description'],
users: json['users'],
createdby: json['createdby'],
);
}
}
\ No newline at end of file
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
class User {
final String username;
final String password;
User({this.username, this.password});
factory User.fromJson(Map<String, dynamic> json) {
return User(
username: json['username'],
password: json['password'],
);
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
class Background extends StatelessWidget {
final Widget child;
const Background({
Key key,
@required this.child,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
height: size.height,
width: double.infinity,
// Here i can use size.width but use double.infinity because both work as a same
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
top: 0,
left: 0,
child: Image.asset(
"assets/images/signup_top.png",
width: size.width * 0.35,
),
),
Positioned(
bottom: 0,
left: 0,
child: Image.asset(
"assets/images/main_bottom.png",
width: size.width * 0.25,
),
),
child,
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Login/login_screen.dart';
import 'package:flutter_auth/Screens/Signup/components/background.dart';
import 'package:flutter_auth/Screens/Signup/components/or_divider.dart';
import 'package:flutter_auth/Screens/Signup/components/social_icon.dart';
import 'package:flutter_auth/components/already_have_an_account_acheck.dart';
import 'package:flutter_auth/components/rounded_button.dart';
import 'package:flutter_auth/components/rounded_input_field.dart';
import 'package:flutter_auth/components/rounded_password_field.dart';
import 'package:flutter_svg/svg.dart';
import '../../Index/index_screen.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
import 'package:flutter_auth/Screens/Model/user.dart';
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Signup/signup_screen.dart';
class Body extends StatelessWidget {
String username;
String password;
String confirm;
int code;
String popuptext;
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Signup",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: size.height * 0.03),
RoundedInputField(
hintText: "Your Login",
onChanged: (value) {
this.username = value;
},
),
RoundedPasswordField(
onChanged: (value) {
this.password = value;
},
),
RoundedPasswordField(
onChanged: (value) {
this.confirm = value;
},
),
RoundedButton(
text: "SIGNUP",
press: () async {
var res = await createUser(this.username, this.password, this.confirm);
if(res == 200) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
if (true) {
return LoginScreen();
}
},
),
);
} else if (res ==409){
this.popuptext = "Le nom d'utilisateur est déja utilisé";
showDialog(
context: context,
builder: (BuildContext context) => _buildPopupDialogUserAlreadyRegistered(context),
);
} else if (res ==400){
this.popuptext = "Les deux mots de passe sont différents";
showDialog(
context: context,
builder: (BuildContext context) => _buildPopupDialogUserAlreadyRegistered(context),
);
}
},
),
SizedBox(height: size.height * 0.03),
AlreadyHaveAnAccountCheck(
login: false,
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen();
},
),
);
},
),
OrDivider(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SocalIcon(
iconSrc: "assets/icons/facebook.svg",
press: () {},
),
SocalIcon(
iconSrc: "assets/icons/twitter.svg",
press: () {},
),
SocalIcon(
iconSrc: "assets/icons/google-plus.svg",
press: () {},
),
],
)
],
),
),
);
}
Widget _buildPopupDialogUserAlreadyRegistered(BuildContext context) {
return new AlertDialog(
title: const Text('Alerte'),
content: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(this.popuptext),
],
),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
textColor: Theme.of(context).primaryColor,
child: const Text('Close'),
),
],
);
}
Future<int> createUser(String username, String password, String confirm) async {
final http.Response response = await http.post(
'http://10.0.2.2:3000/users/',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'username': username,
'password': password,
'confirm': confirm,
}),
);
return response.statusCode;
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/constants.dart';
class OrDivider extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
margin: EdgeInsets.symmetric(vertical: size.height * 0.02),
width: size.width * 0.8,
child: Row(
children: <Widget>[
buildDivider(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
"OR",
style: TextStyle(
color: kPrimaryColor,
fontWeight: FontWeight.w600,
),
),
),
buildDivider(),
],
),
);
}
Expanded buildDivider() {
return Expanded(
child: Divider(
color: Color(0xFFD9D9D9),
height: 1.5,
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_auth/constants.dart';
import 'package:flutter_svg/flutter_svg.dart';
class SocalIcon extends StatelessWidget {
final String iconSrc;
final Function press;
const SocalIcon({
Key key,
this.iconSrc,
this.press,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: press,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
border: Border.all(
width: 2,
color: kPrimaryLightColor,
),
shape: BoxShape.circle,
),
child: SvgPicture.asset(
iconSrc,
height: 20,
width: 20,
),
),
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment