Initialize MVVM architecture
This commit is contained in:
46
lib/views/company_choice.dart
Normal file
46
lib/views/company_choice.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:astronote_app/models/company.dart';
|
||||
|
||||
class CompanyChoiceView extends StatefulWidget {
|
||||
@override
|
||||
_CompanyChoiceViewState createState() => _CompanyChoiceViewState();
|
||||
}
|
||||
|
||||
class _CompanyChoiceViewState extends State<CompanyChoiceView> {
|
||||
Companie companies = new Companie();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
margin: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).size.height * 0.09,
|
||||
bottom: MediaQuery.of(context).size.height * 0.05),
|
||||
padding: EdgeInsets.only(
|
||||
left: MediaQuery.of(context).size.height * 0.05,
|
||||
right: MediaQuery.of(context).size.height * 0.05),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text("Bonjour !", style: Theme.of(context).textTheme.headline1),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.08),
|
||||
Text("Pour quelle enseigne souhaitez-vous gérer vos notes de dépenses ?", style: Theme.of(context).textTheme.headline2,textAlign: TextAlign.center),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.07),
|
||||
ButtonTheme.fromButtonThemeData(
|
||||
data: Theme.of(context).buttonTheme,
|
||||
child: RaisedButton(
|
||||
elevation: 3.0,
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/dashboardScreen');
|
||||
},
|
||||
|
||||
child: Text("C'est parti !",
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.button),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
15
lib/views/dashboard.dart
Normal file
15
lib/views/dashboard.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DashBoardView extends StatefulWidget {
|
||||
@override
|
||||
_DashBoardViewState createState() => _DashBoardViewState();
|
||||
}
|
||||
|
||||
class _DashBoardViewState extends State<DashBoardView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
bottomNavigationBar: BottomAppBar(),
|
||||
);
|
||||
}
|
||||
}
|
||||
186
lib/views/log_in.dart
Normal file
186
lib/views/log_in.dart
Normal file
@@ -0,0 +1,186 @@
|
||||
import 'file:///D:/AndroidStudioProjects/astronote_app/lib/services/log_in_services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class LogInView extends StatefulWidget {
|
||||
// static const routeName = '/logInScreen';
|
||||
|
||||
@override
|
||||
_LogInViewState createState() => _LogInViewState();
|
||||
}
|
||||
|
||||
class _LogInViewState extends State<LogInView> {
|
||||
|
||||
var _obscurePassword = true;
|
||||
var _isLoading = false;
|
||||
|
||||
final urlEndi = "https://endi.coop";
|
||||
final urlAstrolabe = "https://astrolabe.coop";
|
||||
|
||||
final GlobalKey<FormState> _formKey = GlobalKey();
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
|
||||
final TextEditingController urlController = new TextEditingController();
|
||||
final TextEditingController loginController = new TextEditingController();
|
||||
final TextEditingController passwordController = new TextEditingController();
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_formKey.currentState.validate()) {
|
||||
// Invalid!
|
||||
return;
|
||||
}
|
||||
_formKey.currentState.save();
|
||||
|
||||
try {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
await Provider.of<LogIn>(context, listen: false).logIn(
|
||||
urlController.text, loginController.text, passwordController.text);
|
||||
if(Provider.of<LogIn>(context, listen: false).isLog){
|
||||
Navigator.pushNamed(context, '/companyChoiceScreen');
|
||||
}
|
||||
} catch (Exception) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
_scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||
backgroundColor: Colors.red[300],
|
||||
duration: Duration(seconds: 3),
|
||||
content: Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.error_outline),
|
||||
Text(' Les données ne sont pas correctes'),
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextStyle style = Theme.of(context).textTheme.bodyText1;
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
body: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).size.height * 0.04,
|
||||
left: MediaQuery.of(context).size.height * 0.07,
|
||||
right: MediaQuery.of(context).size.height * 0.07),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
"assets/astrolabe_logo.jpg",
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.01),
|
||||
Text("AstroNotes", style: style.copyWith(fontSize: 36.0)),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.08),
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
controller: urlController,
|
||||
style: style,
|
||||
keyboardType: TextInputType.url,
|
||||
decoration: InputDecoration(
|
||||
contentPadding:
|
||||
EdgeInsets.fromLTRB(20.0, 15.0, 0.0, 15.0),
|
||||
labelText: "Lien enDI",
|
||||
suffixIcon:
|
||||
Icon(Icons.link, color: Colors.indigo[900]),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(32.0))),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.03),
|
||||
TextFormField(
|
||||
controller: loginController,
|
||||
style: style,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
decoration: InputDecoration(
|
||||
contentPadding:
|
||||
EdgeInsets.fromLTRB(20.0, 15.0, 0.0, 15.0),
|
||||
labelText: "E-mail",
|
||||
suffixIcon:
|
||||
Icon(Icons.mail, color: Colors.indigo[900]),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(32.0))),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.03),
|
||||
TextFormField(
|
||||
controller: passwordController,
|
||||
style: style,
|
||||
obscureText: _obscurePassword,
|
||||
decoration: InputDecoration(
|
||||
contentPadding:
|
||||
EdgeInsets.fromLTRB(20.0, 15.0, 0.0, 15.0),
|
||||
labelText: "Mot de passe",
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscurePassword
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: Colors.indigo[900]),
|
||||
onPressed: () {
|
||||
setState(
|
||||
() => _obscurePassword = !_obscurePassword);
|
||||
}),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(32.0))),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.07),
|
||||
ButtonTheme.fromButtonThemeData(
|
||||
data: Theme.of(context).buttonTheme,
|
||||
child: RaisedButton(
|
||||
elevation: 3.0,
|
||||
onPressed: () {
|
||||
_submit();
|
||||
},
|
||||
child: _isLoading
|
||||
? CircularProgressIndicator()
|
||||
: Text("Connexion",
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.button),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.08),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
if (await canLaunch(urlEndi)) {
|
||||
await launch(urlEndi);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"En collaboration avec enDI",
|
||||
style: style.copyWith(
|
||||
fontSize: 13.0, decoration: TextDecoration.underline),
|
||||
),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.01),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
if (await canLaunch(urlAstrolabe)) {
|
||||
await launch(urlAstrolabe);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"Développé par Astrolabe",
|
||||
style: style.copyWith(
|
||||
fontSize: 13, decoration: TextDecoration.underline),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user