new shared_prefs and avatar
parent
fee5a06f74
commit
e514a1cd5c
|
|
@ -0,0 +1,25 @@
|
||||||
|
import 'package:objectbox/objectbox.dart';
|
||||||
|
import 'objectbox.g.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
class User {
|
||||||
|
// specify the id
|
||||||
|
@Id()
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
|
int id_utilisateur;
|
||||||
|
String login;
|
||||||
|
String nom;
|
||||||
|
String prenom;
|
||||||
|
String photo;
|
||||||
|
|
||||||
|
User(
|
||||||
|
{this.id = 0,
|
||||||
|
required this.id_utilisateur,
|
||||||
|
required this.login,
|
||||||
|
required this.nom,
|
||||||
|
required this.prenom,
|
||||||
|
required this.photo});
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,8 @@ import 'package:mobdr/cubit/language/language_cubit.dart';
|
||||||
import 'package:mobdr/cubit/language/app_localizations.dart';
|
import 'package:mobdr/cubit/language/app_localizations.dart';
|
||||||
import 'package:mobdr/cubit/language/initial_language.dart';
|
import 'package:mobdr/cubit/language/initial_language.dart';
|
||||||
|
|
||||||
|
import 'package:mobdr/service/shared_prefs.dart';
|
||||||
|
|
||||||
import 'package:mobdr/ui/splash_screen.dart';
|
import 'package:mobdr/ui/splash_screen.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
@ -25,6 +27,8 @@ Future<void> main() async {
|
||||||
// to store the database in.
|
// to store the database in.
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
await SharedPrefs().init();
|
||||||
|
|
||||||
objectbox = await ObjectBox.create();
|
objectbox = await ObjectBox.create();
|
||||||
|
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ This page is used to get data from API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import 'package:mobdr/config/constant.dart';
|
import 'package:mobdr/config/constant.dart';
|
||||||
import 'package:mobdr/service/local_storage.dart';
|
import 'package:mobdr/main.dart';
|
||||||
import 'package:mobdr/model/login.dart';
|
import 'package:mobdr/service/shared_prefs.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
|
|
@ -146,7 +146,39 @@ class ApiProvider {
|
||||||
|
|
||||||
switch (response.data['autorisation']) {
|
switch (response.data['autorisation']) {
|
||||||
case 1:
|
case 1:
|
||||||
LocalStorage.saveLoginData(LoginModel.fromJson(response.data));
|
|
||||||
|
/// save user data
|
||||||
|
SharedPrefs().id_utilisateur = response.data['id_utilisateur'];
|
||||||
|
SharedPrefs().email = response.data['email'];
|
||||||
|
SharedPrefs().expire = response.data['expire'];
|
||||||
|
SharedPrefs().guid = response.data['guid'];
|
||||||
|
SharedPrefs().langage = response.data['langage'];
|
||||||
|
SharedPrefs().last_traduction = response.data['last_traduction'];
|
||||||
|
SharedPrefs().login = response.data['login'];
|
||||||
|
SharedPrefs().nom = response.data['nom'];
|
||||||
|
SharedPrefs().prenom = response.data['prenom'];
|
||||||
|
SharedPrefs().version = response.data['version'];
|
||||||
|
SharedPrefs().photo = response.data['photo'];
|
||||||
|
|
||||||
|
/// get image from url
|
||||||
|
Response ReponseImg =
|
||||||
|
await dio.get(ApiConstants.baseUrl + response.data['photo'],
|
||||||
|
options: Options(
|
||||||
|
responseType: ResponseType.bytes,
|
||||||
|
contentType: 'application/octet-stream',
|
||||||
|
));
|
||||||
|
|
||||||
|
/// convert bytes to base64 string
|
||||||
|
String base64Photo = base64.encode(ReponseImg.data);
|
||||||
|
|
||||||
|
/// create box user
|
||||||
|
objectbox.addUSer(
|
||||||
|
response.data['id_utilisateur'],
|
||||||
|
response.data['login'],
|
||||||
|
response.data['nom'],
|
||||||
|
response.data['prenom'],
|
||||||
|
base64Photo);
|
||||||
|
|
||||||
return 'OK';
|
return 'OK';
|
||||||
case -1:
|
case -1:
|
||||||
return 'Compte désactivé ...';
|
return 'Compte désactivé ...';
|
||||||
|
|
@ -260,6 +292,7 @@ class ApiProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
Future<List<LoginModel>> login2(
|
Future<List<LoginModel>> login2(
|
||||||
String email, String password, apiToken) async {
|
String email, String password, apiToken) async {
|
||||||
var postData = {
|
var postData = {
|
||||||
|
|
@ -276,6 +309,7 @@ class ApiProvider {
|
||||||
throw response.data['msg'];
|
throw response.data['msg'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Future<List<ProductGridModel>> getProductGrid(
|
Future<List<ProductGridModel>> getProductGrid(
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,61 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"relations": []
|
"relations": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3:6664528022814238868",
|
||||||
|
"lastPropertyId": "6:1514784951041121129",
|
||||||
|
"name": "User",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "1:4611296599843691135",
|
||||||
|
"name": "id",
|
||||||
|
"type": 6,
|
||||||
|
"flags": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2:3082719507680383784",
|
||||||
|
"name": "photo",
|
||||||
|
"type": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3:6869254152255514608",
|
||||||
|
"name": "login",
|
||||||
|
"type": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4:3830288742147875657",
|
||||||
|
"name": "nom",
|
||||||
|
"type": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "5:1856556503877986423",
|
||||||
|
"name": "prenom",
|
||||||
|
"type": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6:1514784951041121129",
|
||||||
|
"name": "id_utilisateur",
|
||||||
|
"type": 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relations": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"lastEntityId": "1:2802681814019499133",
|
"lastEntityId": "3:6664528022814238868",
|
||||||
"lastIndexId": "0:0",
|
"lastIndexId": "0:0",
|
||||||
"lastRelationId": "0:0",
|
"lastRelationId": "0:0",
|
||||||
"lastSequenceId": "0:0",
|
"lastSequenceId": "0:0",
|
||||||
"modelVersion": 5,
|
"modelVersion": 5,
|
||||||
"modelVersionParserMinimum": 5,
|
"modelVersionParserMinimum": 5,
|
||||||
"retiredEntityUids": [],
|
"retiredEntityUids": [
|
||||||
|
7401686910042688313
|
||||||
|
],
|
||||||
"retiredIndexUids": [],
|
"retiredIndexUids": [],
|
||||||
"retiredPropertyUids": [],
|
"retiredPropertyUids": [
|
||||||
|
402019719780433349,
|
||||||
|
2876428622751679696
|
||||||
|
],
|
||||||
"retiredRelationUids": [],
|
"retiredRelationUids": [],
|
||||||
"version": 1
|
"version": 1
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'box_user.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
import 'objectbox.g.dart'; // created by `flutter pub run build_runner build`
|
import 'objectbox.g.dart'; // created by `flutter pub run build_runner build`
|
||||||
|
|
||||||
|
|
@ -11,13 +12,24 @@ class ObjectBox {
|
||||||
/// A Box of notes.
|
/// A Box of notes.
|
||||||
late final Box<Note> noteBox;
|
late final Box<Note> noteBox;
|
||||||
|
|
||||||
|
/// A Box of user.
|
||||||
|
late final Box<User> userBox;
|
||||||
|
|
||||||
ObjectBox._create(this.store) {
|
ObjectBox._create(this.store) {
|
||||||
noteBox = Box<Note>(store);
|
noteBox = Box<Note>(store);
|
||||||
|
userBox = Box<User>(store);
|
||||||
|
|
||||||
// Add some demo data if the box is empty.
|
// Add some demo data if the box is empty.
|
||||||
if (noteBox.isEmpty()) {
|
if (noteBox.isEmpty()) {
|
||||||
_putDemoData();
|
_putDemoData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userBox.removeAll();
|
||||||
|
|
||||||
|
// Add some demo data if the box is empty.
|
||||||
|
if (userBox.isEmpty()) {
|
||||||
|
_putUserAdminData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an instance of ObjectBox to use throughout the app.
|
/// Create an instance of ObjectBox to use throughout the app.
|
||||||
|
|
@ -36,6 +48,17 @@ class ObjectBox {
|
||||||
store.runInTransactionAsync(TxMode.write, _putNotesInTx, demoNotes);
|
store.runInTransactionAsync(TxMode.write, _putNotesInTx, demoNotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getUserAvatar(int id_utilisateur) {
|
||||||
|
final query =
|
||||||
|
userBox.query(User_.id_utilisateur.equals(id_utilisateur)).build();
|
||||||
|
var p = query.findFirst();
|
||||||
|
return p!.photo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _putUserAdminData() {
|
||||||
|
//addUSer(0, 'root', 'admim', 'admin', '');
|
||||||
|
}
|
||||||
|
|
||||||
Stream<List<Note>> getNotes() {
|
Stream<List<Note>> getNotes() {
|
||||||
// Query for all notes, sorted by their date.
|
// Query for all notes, sorted by their date.
|
||||||
// https://docs.objectbox.io/queries
|
// https://docs.objectbox.io/queries
|
||||||
|
|
@ -69,4 +92,22 @@ class ObjectBox {
|
||||||
// here. To keep it simple, this example just puts a single object.
|
// here. To keep it simple, this example just puts a single object.
|
||||||
store.box<Note>().put(Note(text));
|
store.box<Note>().put(Note(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> addUSer(int _id_utilisateur, String _login, String _nom,
|
||||||
|
String _prenom, String _photo) =>
|
||||||
|
store.runInTransactionAsync(
|
||||||
|
TxMode.write,
|
||||||
|
_addUserInTx,
|
||||||
|
User(
|
||||||
|
id_utilisateur: _id_utilisateur,
|
||||||
|
login: _login,
|
||||||
|
nom: _nom,
|
||||||
|
prenom: _prenom,
|
||||||
|
photo: _photo));
|
||||||
|
|
||||||
|
static void _addUserInTx(Store store, _User) {
|
||||||
|
// Perform ObjectBox operations that take longer than a few milliseconds
|
||||||
|
// here. To keep it simple, this example just puts a single object.
|
||||||
|
store.box<User>().put(_User);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import 'package:objectbox/internal.dart'; // generated code can access "internal
|
||||||
import 'package:objectbox/objectbox.dart';
|
import 'package:objectbox/objectbox.dart';
|
||||||
import 'package:objectbox_flutter_libs/objectbox_flutter_libs.dart';
|
import 'package:objectbox_flutter_libs/objectbox_flutter_libs.dart';
|
||||||
|
|
||||||
|
import 'box_user.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
|
|
||||||
export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file
|
export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file
|
||||||
|
|
@ -47,6 +48,45 @@ final _entities = <ModelEntity>[
|
||||||
flags: 0)
|
flags: 0)
|
||||||
],
|
],
|
||||||
relations: <ModelRelation>[],
|
relations: <ModelRelation>[],
|
||||||
|
backlinks: <ModelBacklink>[]),
|
||||||
|
ModelEntity(
|
||||||
|
id: const IdUid(3, 6664528022814238868),
|
||||||
|
name: 'User',
|
||||||
|
lastPropertyId: const IdUid(6, 1514784951041121129),
|
||||||
|
flags: 0,
|
||||||
|
properties: <ModelProperty>[
|
||||||
|
ModelProperty(
|
||||||
|
id: const IdUid(1, 4611296599843691135),
|
||||||
|
name: 'id',
|
||||||
|
type: 6,
|
||||||
|
flags: 1),
|
||||||
|
ModelProperty(
|
||||||
|
id: const IdUid(2, 3082719507680383784),
|
||||||
|
name: 'photo',
|
||||||
|
type: 9,
|
||||||
|
flags: 0),
|
||||||
|
ModelProperty(
|
||||||
|
id: const IdUid(3, 6869254152255514608),
|
||||||
|
name: 'login',
|
||||||
|
type: 9,
|
||||||
|
flags: 0),
|
||||||
|
ModelProperty(
|
||||||
|
id: const IdUid(4, 3830288742147875657),
|
||||||
|
name: 'nom',
|
||||||
|
type: 9,
|
||||||
|
flags: 0),
|
||||||
|
ModelProperty(
|
||||||
|
id: const IdUid(5, 1856556503877986423),
|
||||||
|
name: 'prenom',
|
||||||
|
type: 9,
|
||||||
|
flags: 0),
|
||||||
|
ModelProperty(
|
||||||
|
id: const IdUid(6, 1514784951041121129),
|
||||||
|
name: 'id_utilisateur',
|
||||||
|
type: 6,
|
||||||
|
flags: 0)
|
||||||
|
],
|
||||||
|
relations: <ModelRelation>[],
|
||||||
backlinks: <ModelBacklink>[])
|
backlinks: <ModelBacklink>[])
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -70,13 +110,13 @@ Future<Store> openStore(
|
||||||
ModelDefinition getObjectBoxModel() {
|
ModelDefinition getObjectBoxModel() {
|
||||||
final model = ModelInfo(
|
final model = ModelInfo(
|
||||||
entities: _entities,
|
entities: _entities,
|
||||||
lastEntityId: const IdUid(1, 2802681814019499133),
|
lastEntityId: const IdUid(3, 6664528022814238868),
|
||||||
lastIndexId: const IdUid(0, 0),
|
lastIndexId: const IdUid(0, 0),
|
||||||
lastRelationId: const IdUid(0, 0),
|
lastRelationId: const IdUid(0, 0),
|
||||||
lastSequenceId: const IdUid(0, 0),
|
lastSequenceId: const IdUid(0, 0),
|
||||||
retiredEntityUids: const [],
|
retiredEntityUids: const [7401686910042688313],
|
||||||
retiredIndexUids: const [],
|
retiredIndexUids: const [],
|
||||||
retiredPropertyUids: const [],
|
retiredPropertyUids: const [402019719780433349, 2876428622751679696],
|
||||||
retiredRelationUids: const [],
|
retiredRelationUids: const [],
|
||||||
modelVersion: 5,
|
modelVersion: 5,
|
||||||
modelVersionParserMinimum: 5,
|
modelVersionParserMinimum: 5,
|
||||||
|
|
@ -116,6 +156,48 @@ ModelDefinition getObjectBoxModel() {
|
||||||
date: DateTime.fromMillisecondsSinceEpoch(
|
date: DateTime.fromMillisecondsSinceEpoch(
|
||||||
const fb.Int64Reader().vTableGet(buffer, rootOffset, 10, 0)));
|
const fb.Int64Reader().vTableGet(buffer, rootOffset, 10, 0)));
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}),
|
||||||
|
User: EntityDefinition<User>(
|
||||||
|
model: _entities[1],
|
||||||
|
toOneRelations: (User object) => [],
|
||||||
|
toManyRelations: (User object) => {},
|
||||||
|
getId: (User object) => object.id,
|
||||||
|
setId: (User object, int id) {
|
||||||
|
object.id = id;
|
||||||
|
},
|
||||||
|
objectToFB: (User object, fb.Builder fbb) {
|
||||||
|
final photoOffset = fbb.writeString(object.photo);
|
||||||
|
final loginOffset = fbb.writeString(object.login);
|
||||||
|
final nomOffset = fbb.writeString(object.nom);
|
||||||
|
final prenomOffset = fbb.writeString(object.prenom);
|
||||||
|
fbb.startTable(7);
|
||||||
|
fbb.addInt64(0, object.id);
|
||||||
|
fbb.addOffset(1, photoOffset);
|
||||||
|
fbb.addOffset(2, loginOffset);
|
||||||
|
fbb.addOffset(3, nomOffset);
|
||||||
|
fbb.addOffset(4, prenomOffset);
|
||||||
|
fbb.addInt64(5, object.id_utilisateur);
|
||||||
|
fbb.finish(fbb.endTable());
|
||||||
|
return object.id;
|
||||||
|
},
|
||||||
|
objectFromFB: (Store store, ByteData fbData) {
|
||||||
|
final buffer = fb.BufferContext(fbData);
|
||||||
|
final rootOffset = buffer.derefObject(0);
|
||||||
|
|
||||||
|
final object = User(
|
||||||
|
id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0),
|
||||||
|
id_utilisateur:
|
||||||
|
const fb.Int64Reader().vTableGet(buffer, rootOffset, 14, 0),
|
||||||
|
login: const fb.StringReader(asciiOptimization: true)
|
||||||
|
.vTableGet(buffer, rootOffset, 8, ''),
|
||||||
|
nom: const fb.StringReader(asciiOptimization: true)
|
||||||
|
.vTableGet(buffer, rootOffset, 10, ''),
|
||||||
|
prenom: const fb.StringReader(asciiOptimization: true)
|
||||||
|
.vTableGet(buffer, rootOffset, 12, ''),
|
||||||
|
photo: const fb.StringReader(asciiOptimization: true)
|
||||||
|
.vTableGet(buffer, rootOffset, 6, ''));
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
@ -137,3 +219,25 @@ class Note_ {
|
||||||
/// see [Note.date]
|
/// see [Note.date]
|
||||||
static final date = QueryIntegerProperty<Note>(_entities[0].properties[3]);
|
static final date = QueryIntegerProperty<Note>(_entities[0].properties[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [User] entity fields to define ObjectBox queries.
|
||||||
|
class User_ {
|
||||||
|
/// see [User.id]
|
||||||
|
static final id = QueryIntegerProperty<User>(_entities[1].properties[0]);
|
||||||
|
|
||||||
|
/// see [User.photo]
|
||||||
|
static final photo = QueryStringProperty<User>(_entities[1].properties[1]);
|
||||||
|
|
||||||
|
/// see [User.login]
|
||||||
|
static final login = QueryStringProperty<User>(_entities[1].properties[2]);
|
||||||
|
|
||||||
|
/// see [User.nom]
|
||||||
|
static final nom = QueryStringProperty<User>(_entities[1].properties[3]);
|
||||||
|
|
||||||
|
/// see [User.prenom]
|
||||||
|
static final prenom = QueryStringProperty<User>(_entities[1].properties[4]);
|
||||||
|
|
||||||
|
/// see [User.id_utilisateur]
|
||||||
|
static final id_utilisateur =
|
||||||
|
QueryIntegerProperty<User>(_entities[1].properties[5]);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'package:mobdr/model/login.dart';
|
import 'package:mobdr/old/login.dart';
|
||||||
import 'package:mobdr/model/user_profile.dart';
|
import 'package:mobdr/old/user_profile.dart';
|
||||||
|
|
||||||
class LocalStorage {
|
class LocalStorage {
|
||||||
// static Future<SharedPreferences> get securePref async =>
|
// static Future<SharedPreferences> get securePref async =>
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class SharedPrefs {
|
||||||
|
static late SharedPreferences _sharedPrefs;
|
||||||
|
|
||||||
|
factory SharedPrefs() => SharedPrefs._internal();
|
||||||
|
|
||||||
|
SharedPrefs._internal();
|
||||||
|
|
||||||
|
Future<void> init() async {
|
||||||
|
_sharedPrefs = await SharedPreferences.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set id_utilisateur
|
||||||
|
int get id_utilisateur => _sharedPrefs.getInt('key_id_utilisateur') ?? 0;
|
||||||
|
|
||||||
|
set id_utilisateur(int value) {
|
||||||
|
_sharedPrefs.setInt('key_id_utilisateur', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set expire
|
||||||
|
int get expire => _sharedPrefs.getInt('key_expire') ?? 0;
|
||||||
|
|
||||||
|
set expire(int value) {
|
||||||
|
_sharedPrefs.setInt('key_expire', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set email
|
||||||
|
String get email => _sharedPrefs.getString('key_email') ?? "";
|
||||||
|
|
||||||
|
set email(String value) {
|
||||||
|
_sharedPrefs.setString('key_email', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set guid
|
||||||
|
String get guid => _sharedPrefs.getString('key_guid') ?? "";
|
||||||
|
|
||||||
|
set guid(String value) {
|
||||||
|
_sharedPrefs.setString('key_guid', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set langage
|
||||||
|
String get langage => _sharedPrefs.getString('key_langage') ?? "";
|
||||||
|
|
||||||
|
set langage(String value) {
|
||||||
|
_sharedPrefs.setString('key_langage', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set last_traduction
|
||||||
|
String get last_traduction =>
|
||||||
|
_sharedPrefs.getString('key_last_traduction') ?? "";
|
||||||
|
|
||||||
|
set last_traduction(String value) {
|
||||||
|
_sharedPrefs.setString('key_last_traduction', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set login
|
||||||
|
String get login => _sharedPrefs.getString('key_login') ?? "";
|
||||||
|
|
||||||
|
set login(String value) {
|
||||||
|
_sharedPrefs.setString('key_login', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set nom
|
||||||
|
String get nom => _sharedPrefs.getString('key_nom') ?? "";
|
||||||
|
|
||||||
|
set nom(String value) {
|
||||||
|
_sharedPrefs.setString('key_nom', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set prenom
|
||||||
|
String get prenom => _sharedPrefs.getString('key_prenom') ?? "";
|
||||||
|
|
||||||
|
set prenom(String value) {
|
||||||
|
_sharedPrefs.setString('key_prenom', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set version
|
||||||
|
String get version => _sharedPrefs.getString('key_version') ?? "";
|
||||||
|
|
||||||
|
set version(String value) {
|
||||||
|
_sharedPrefs.setString('key_version', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get/set photo
|
||||||
|
String get photo => _sharedPrefs.getString('key_photo') ?? "";
|
||||||
|
|
||||||
|
set photo(String value) {
|
||||||
|
_sharedPrefs.setString('key_photo', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:mobdr/config/constant.dart';
|
import 'package:mobdr/config/constant.dart';
|
||||||
import 'package:mobdr/config/global_style.dart';
|
import 'package:mobdr/config/global_style.dart';
|
||||||
|
import 'package:mobdr/service/shared_prefs.dart';
|
||||||
import 'package:mobdr/ui/account/account_information/edit_email.dart';
|
import 'package:mobdr/ui/account/account_information/edit_email.dart';
|
||||||
import 'package:mobdr/ui/account/account_information/edit_name.dart';
|
import 'package:mobdr/ui/account/account_information/edit_name.dart';
|
||||||
import 'package:mobdr/ui/account/account_information/edit_phone_number.dart';
|
import 'package:mobdr/ui/account/account_information/edit_phone_number.dart';
|
||||||
|
|
@ -16,7 +17,6 @@ class AccountInformationPage extends StatefulWidget {
|
||||||
class _AccountInformationPageState extends State<AccountInformationPage> {
|
class _AccountInformationPageState extends State<AccountInformationPage> {
|
||||||
// initialize reusable widget
|
// initialize reusable widget
|
||||||
final _reusableWidget = ReusableWidget();
|
final _reusableWidget = ReusableWidget();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
@ -63,7 +63,7 @@ class _AccountInformationPageState extends State<AccountInformationPage> {
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Robert Steven',
|
"${SharedPrefs().prenom} ${SharedPrefs().nom}",
|
||||||
style: GlobalStyle.accountInformationValue,
|
style: GlobalStyle.accountInformationValue,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ we used AutomaticKeepAliveClientMixin to keep the state when moving from 1 navba
|
||||||
|
|
||||||
import 'package:mobdr/config/constant.dart';
|
import 'package:mobdr/config/constant.dart';
|
||||||
import 'package:mobdr/config/global_style.dart';
|
import 'package:mobdr/config/global_style.dart';
|
||||||
|
import 'package:mobdr/service/shared_prefs.dart';
|
||||||
import 'package:mobdr/ui/account/about.dart';
|
import 'package:mobdr/ui/account/about.dart';
|
||||||
import 'package:mobdr/ui/account/account_information/account_information.dart';
|
import 'package:mobdr/ui/account/account_information/account_information.dart';
|
||||||
import 'package:mobdr/ui/account/last_seen_product.dart';
|
import 'package:mobdr/ui/account/last_seen_product.dart';
|
||||||
|
|
@ -17,9 +18,10 @@ import 'package:mobdr/ui/account/terms_conditions.dart';
|
||||||
import 'package:mobdr/ui/general/chat_us.dart';
|
import 'package:mobdr/ui/general/chat_us.dart';
|
||||||
import 'package:mobdr/ui/general/notification.dart';
|
import 'package:mobdr/ui/general/notification.dart';
|
||||||
import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
||||||
import 'package:mobdr/ui/reusable/cache_image_network.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobdr/ui/authentication/signin.dart';
|
import 'package:mobdr/ui/authentication/signin.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:mobdr/main.dart';
|
||||||
|
|
||||||
class TabAccountPage extends StatefulWidget {
|
class TabAccountPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -31,6 +33,11 @@ class _TabAccountPageState extends State<TabAccountPage>
|
||||||
// initialize reusable widget
|
// initialize reusable widget
|
||||||
final _reusableWidget = ReusableWidget();
|
final _reusableWidget = ReusableWidget();
|
||||||
|
|
||||||
|
Image imageFromBase64String() {
|
||||||
|
String base64String = objectbox.getUserAvatar(SharedPrefs().id_utilisateur);
|
||||||
|
return Image.memory(base64Decode(base64String));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
|
|
@ -157,11 +164,7 @@ class _TabAccountPageState extends State<TabAccountPage>
|
||||||
radius: profilePictureSize - 4,
|
radius: profilePictureSize - 4,
|
||||||
child: Hero(
|
child: Hero(
|
||||||
tag: 'profilePicture',
|
tag: 'profilePicture',
|
||||||
child: ClipOval(
|
child: ClipOval(child: imageFromBase64String()),
|
||||||
child: buildCacheNetworkImage(
|
|
||||||
width: profilePictureSize - 4,
|
|
||||||
height: profilePictureSize - 4,
|
|
||||||
url: GLOBAL_URL + '/user/avatar.png')),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -174,7 +177,7 @@ class _TabAccountPageState extends State<TabAccountPage>
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text('Robert Steven',
|
Text("${SharedPrefs().prenom} ${SharedPrefs().nom}",
|
||||||
style:
|
style:
|
||||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import 'package:mobdr/config/constant.dart';
|
||||||
import 'package:mobdr/cubit/language/language_cubit.dart';
|
import 'package:mobdr/cubit/language/language_cubit.dart';
|
||||||
import 'package:mobdr/cubit/language/app_localizations.dart';
|
import 'package:mobdr/cubit/language/app_localizations.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:mobdr/service/shared_prefs.dart';
|
||||||
import 'package:mobdr/config/global_style.dart';
|
import 'package:mobdr/config/global_style.dart';
|
||||||
import 'package:mobdr/model/wishlist_model.dart';
|
import 'package:mobdr/model/wishlist_model.dart';
|
||||||
import 'package:mobdr/ui/general/chat_us.dart';
|
import 'package:mobdr/ui/general/chat_us.dart';
|
||||||
|
|
@ -16,7 +17,6 @@ import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
||||||
import 'package:mobdr/ui/reusable/cache_image_network.dart';
|
import 'package:mobdr/ui/reusable/cache_image_network.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:mobdr/service/local_storage.dart';
|
|
||||||
|
|
||||||
class TabHomePage extends StatefulWidget {
|
class TabHomePage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -36,21 +36,19 @@ class _TabHomePageState extends State<TabHomePage>
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
String defaultLang = 'en';
|
String defaultLang = 'en';
|
||||||
String UserName = '';
|
|
||||||
|
|
||||||
late LanguageCubit _languageCubit;
|
late LanguageCubit _languageCubit;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_languageCubit = BlocProvider.of<LanguageCubit>(context);
|
_languageCubit = BlocProvider.of<LanguageCubit>(context);
|
||||||
|
|
||||||
_getLocale().then((val) {
|
_getLocale().then((val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
defaultLang = val!;
|
defaultLang = val!;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
LocalStorage.getLoginData().then((value) => UserName = value!.prenom);
|
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,8 +82,7 @@ class _TabHomePageState extends State<TabHomePage>
|
||||||
elevation: GlobalStyle.appBarElevation,
|
elevation: GlobalStyle.appBarElevation,
|
||||||
title: Text(
|
title: Text(
|
||||||
AppLocalizations.of(context)!.translate('i18n_hello')! +
|
AppLocalizations.of(context)!.translate('i18n_hello')! +
|
||||||
', ' +
|
', ${SharedPrefs().prenom}',
|
||||||
UserName,
|
|
||||||
style: GlobalStyle.appBarTitle,
|
style: GlobalStyle.appBarTitle,
|
||||||
),
|
),
|
||||||
backgroundColor: GlobalStyle.appBarBackgroundColor,
|
backgroundColor: GlobalStyle.appBarBackgroundColor,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue