Initialize MVVM architecture
This commit is contained in:
parent
4d6ca678fc
commit
8257eadee5
@ -1,14 +1,15 @@
|
||||
import 'package:astronote_app/screens/company_choice_screen.dart';
|
||||
import 'package:astronote_app/screens/dashboard_screen.dart';
|
||||
import 'package:astronote_app/screens/log_in_screen.dart';
|
||||
import 'package:astronote_app/providers/log_in.dart';
|
||||
import 'package:astronote_app/theme/style.dart';
|
||||
import 'file:///D:/AndroidStudioProjects/astronote_app/lib/services/log_in_services.dart';
|
||||
import 'package:astronote_app/themes/style.dart';
|
||||
import 'package:astronote_app/views/company_choice.dart';
|
||||
import 'package:astronote_app/views/dashboard.dart';
|
||||
import 'package:astronote_app/views/log_in.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
@ -19,11 +20,11 @@ class MyApp extends StatelessWidget {
|
||||
builder:(context, logIn, _) => MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: appTheme(),
|
||||
home: logIn.isLog ? CompanyChoiceScreen() : LogInScreen(),
|
||||
home: logIn.isLog ? CompanyChoiceView() : LogInView(),
|
||||
routes: {
|
||||
"/logInScreen": (context) => LogInScreen(),
|
||||
"/companyChoiceScreen": (context) => CompanyChoiceScreen(),
|
||||
"/dashboardScreen": (context) => DashBoardScreen()
|
||||
"/logInScreen": (context) => LogInView(),
|
||||
"/companyChoiceScreen": (context) => CompanyChoiceView(),
|
||||
"/dashboardScreen": (context) => DashBoardView()
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -1,15 +1,15 @@
|
||||
import 'package:astronote_app/models/companie.dart';
|
||||
import 'package:astronote_app/models/company.dart';
|
||||
|
||||
class User {
|
||||
class UserDatas {
|
||||
String lastname;
|
||||
List<Companie> companies;
|
||||
String firstname;
|
||||
String civilite;
|
||||
|
||||
User({this.lastname, this.companies, this.firstname, this.civilite});
|
||||
UserDatas({this.lastname, this.companies, this.firstname, this.civilite});
|
||||
|
||||
|
||||
User.fromJson(Map<String, dynamic> json) {
|
||||
UserDatas.fromJson(Map<String, dynamic> json) {
|
||||
lastname = json['lastname'];
|
||||
if (json['companies'] != null) {
|
||||
companies = new List<Companie>();
|
||||
|
@ -1,59 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DashBoardScreen extends StatefulWidget {
|
||||
@override
|
||||
_DashBoardScreenState createState() => _DashBoardScreenState();
|
||||
}
|
||||
|
||||
class _DashBoardScreenState extends State<DashBoardScreen> {
|
||||
int _selectedIndex = 0;
|
||||
static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
|
||||
static const List<Widget> _widgetOptions = <Widget>[
|
||||
Text(
|
||||
'Index 0: Accueil',
|
||||
style: optionStyle,
|
||||
),
|
||||
Text(
|
||||
'Index 1: Notes',
|
||||
style: optionStyle,
|
||||
),
|
||||
Text(
|
||||
'Index 2: Enseignes',
|
||||
style: optionStyle,
|
||||
),
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: _widgetOptions.elementAt(_selectedIndex),
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: const <BottomNavigationBarItem>[
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
title: Text('Accueil'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.add),
|
||||
title: Text('Notes'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.business),
|
||||
title: Text('Enseignes'),
|
||||
),
|
||||
],
|
||||
currentIndex: _selectedIndex,
|
||||
selectedItemColor: Colors.indigo[900],
|
||||
onTap: _onItemTapped,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:astronote_app/models/user_datas.dart';
|
||||
import 'package:astronote_app/models/credential.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -37,7 +35,6 @@ class LogIn with ChangeNotifier {
|
||||
_cookie = response.headers['set-cookie'];
|
||||
_userCredentials = new Credential(url: url, login: login, password: password);
|
||||
print(_userCredentials.toString());
|
||||
// await OpenLocalBdd();
|
||||
return recoverUserDatas(urlApi);
|
||||
} else{
|
||||
_cookie = null;
|
||||
@ -58,32 +55,9 @@ class LogIn with ChangeNotifier {
|
||||
// If the server did return a 200 OK response then parse the JSON.
|
||||
final responseJson = json.decode(response.body);
|
||||
|
||||
User userDatas = new User.fromJson(responseJson['datas']);
|
||||
UserDatas userDatas = new UserDatas.fromJson(responseJson['datas']);
|
||||
print(userDatas.companies[0].toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Future<Database> OpenLocalBdd() async {
|
||||
// // Open the database and store the reference.
|
||||
// final Future<Database> database = openDatabase(
|
||||
// // Set the path to the database. Note: Using the `join` function from the
|
||||
// // `path` package is best practice to ensure the path is correctly
|
||||
// // constructed for each platform.
|
||||
// join(await getDatabasesPath(), 'astronote_database.db'),
|
||||
// onCreate: (db, version) {
|
||||
// // Run the CREATE TABLE statement on the database.
|
||||
// return db.execute(
|
||||
// "CREATE TABLE credentials(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)",
|
||||
// );
|
||||
// },
|
||||
// // Set the version. This executes the onCreate function and provides a
|
||||
// // path to perform database upgrades and downgrades.
|
||||
// version: 1,
|
||||
//
|
||||
// );
|
||||
// print(await getDatabasesPath());
|
||||
// await database;
|
||||
// }
|
||||
|
||||
|
||||
}
|
21
lib/viewmodels/db.dart
Normal file
21
lib/viewmodels/db.dart
Normal file
@ -0,0 +1,21 @@
|
||||
// Future<Database> OpenLocalBdd() async {
|
||||
// // Open the database and store the reference.
|
||||
// final Future<Database> database = openDatabase(
|
||||
// // Set the path to the database. Note: Using the `join` function from the
|
||||
// // `path` package is best practice to ensure the path is correctly
|
||||
// // constructed for each platform.
|
||||
// join(await getDatabasesPath(), 'astronote_database.db'),
|
||||
// onCreate: (db, version) {
|
||||
// // Run the CREATE TABLE statement on the database.
|
||||
// return db.execute(
|
||||
// "CREATE TABLE credentials(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)",
|
||||
// );
|
||||
// },
|
||||
// // Set the version. This executes the onCreate function and provides a
|
||||
// // path to perform database upgrades and downgrades.
|
||||
// version: 1,
|
||||
//
|
||||
// );
|
||||
// print(await getDatabasesPath());
|
||||
// await database;
|
||||
// }
|
@ -1,12 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:astronote_app/models/companie.dart';
|
||||
import 'package:astronote_app/models/company.dart';
|
||||
|
||||
class CompanyChoiceScreen extends StatefulWidget {
|
||||
class CompanyChoiceView extends StatefulWidget {
|
||||
@override
|
||||
_CompanyChoiceScreenState createState() => _CompanyChoiceScreenState();
|
||||
_CompanyChoiceViewState createState() => _CompanyChoiceViewState();
|
||||
}
|
||||
|
||||
class _CompanyChoiceScreenState extends State<CompanyChoiceScreen> {
|
||||
class _CompanyChoiceViewState extends State<CompanyChoiceView> {
|
||||
Companie companies = new Companie();
|
||||
|
||||
@override
|
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(),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
import 'package:astronote_app/providers/log_in.dart';
|
||||
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 LogInScreen extends StatefulWidget {
|
||||
class LogInView extends StatefulWidget {
|
||||
// static const routeName = '/logInScreen';
|
||||
|
||||
@override
|
||||
_LogInScreenState createState() => _LogInScreenState();
|
||||
_LogInViewState createState() => _LogInViewState();
|
||||
}
|
||||
|
||||
class _LogInScreenState extends State<LogInScreen> {
|
||||
class _LogInViewState extends State<LogInView> {
|
||||
|
||||
var _obscurePassword = true;
|
||||
var _isLoading = false;
|
Loading…
Reference in New Issue
Block a user