Download from api and store it locally (config, section, resource) + wip display in article page
This commit is contained in:
parent
357fa2f235
commit
4802929fa8
@ -1 +1 @@
|
|||||||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"qr_code_scanner","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-08-25 17:55:14.179888","version":"3.0.3"}
|
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"qr_code_scanner","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-08-26 18:14:06.211747","version":"3.0.3"}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:manager_api/api.dart';
|
import 'package:manager_api/api.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Models/resourceModel.dart';
|
||||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
@ -101,7 +102,6 @@ class DatabaseHelper {
|
|||||||
await db.execute('''
|
await db.execute('''
|
||||||
CREATE TABLE $resourcesTable (
|
CREATE TABLE $resourcesTable (
|
||||||
$columnId TEXT NOT NULL PRIMARY KEY,
|
$columnId TEXT NOT NULL PRIMARY KEY,
|
||||||
$columnLabel TEXT NOT NULL,
|
|
||||||
$columnData TEXT NOT NULL,
|
$columnData TEXT NOT NULL,
|
||||||
$columnType INT NOT NULL
|
$columnType INT NOT NULL
|
||||||
)
|
)
|
||||||
@ -118,9 +118,24 @@ class DatabaseHelper {
|
|||||||
}
|
}
|
||||||
var test = await instance.getData(type);
|
var test = await instance.getData(type);
|
||||||
if((type == DatabaseTableType.main && test != null) || (type != DatabaseTableType.main && test!.where((t) => info[columnId] == t.id).isNotEmpty)) {
|
if((type == DatabaseTableType.main && test != null) || (type != DatabaseTableType.main && test!.where((t) => info[columnId] == t.id).isNotEmpty)) {
|
||||||
var res = await db.update(_getTableName(type), info);
|
if(type != DatabaseTableType.main) {
|
||||||
|
print("UPDATE $type - length before ${test.length}");
|
||||||
|
} else {
|
||||||
|
print("UPDATE $type - main table");
|
||||||
|
}
|
||||||
|
var res = await db.update(
|
||||||
|
_getTableName(type),
|
||||||
|
info,
|
||||||
|
where: "$columnId = ?",
|
||||||
|
whereArgs: [info[columnId]],
|
||||||
|
);
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
|
if(type != DatabaseTableType.main) {
|
||||||
|
print("INSERT $type - length before ${test.length}");
|
||||||
|
} else {
|
||||||
|
print("INSERT $type - main table");
|
||||||
|
}
|
||||||
var res = await db.insert(_getTableName(type), info);
|
var res = await db.insert(_getTableName(type), info);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -144,6 +159,12 @@ class DatabaseHelper {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<Map<String, dynamic>>> queryWithId(DatabaseTableType type, String id) async {
|
||||||
|
Database db = await instance.database;
|
||||||
|
var res = await db.query(_getTableName(type), where: '$columnId = ?', whereArgs: [id]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
Future<int> delete(String id, DatabaseTableType type) async {
|
Future<int> delete(String id, DatabaseTableType type) async {
|
||||||
Database db = await instance.database;
|
Database db = await instance.database;
|
||||||
return await db.delete(_getTableName(type), where: '$columnId = ?', whereArgs: [id]);
|
return await db.delete(_getTableName(type), where: '$columnId = ?', whereArgs: [id]);
|
||||||
@ -164,10 +185,8 @@ class DatabaseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await DatabaseHelper.instance.queryAllRows(type).then((value) {
|
await DatabaseHelper.instance.queryAllRows(type).then((value) {
|
||||||
print("value -----");
|
print("DB - getData - CONTEXT --- $type --> ");
|
||||||
print(value);
|
|
||||||
value.forEach((element) {
|
value.forEach((element) {
|
||||||
print("DB - CONTEXT --- ");
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case DatabaseTableType.main:
|
case DatabaseTableType.main:
|
||||||
dataToReturn = VisitAppContext(
|
dataToReturn = VisitAppContext(
|
||||||
@ -176,52 +195,19 @@ class DatabaseHelper {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case DatabaseTableType.configurations:
|
case DatabaseTableType.configurations:
|
||||||
dataToReturn.add(ConfigurationDTO(
|
dataToReturn.add(getConfigurationFromDB(element));
|
||||||
id: element["id"],
|
|
||||||
label: element["label"],
|
|
||||||
primaryColor: element["primaryColor"],
|
|
||||||
secondaryColor: element["secondaryColor"],
|
|
||||||
languages: List<String>.from(jsonDecode(element["languages"])),
|
|
||||||
dateCreation: DateTime.tryParse(element["dateCreation"]),
|
|
||||||
isMobile: element["isMobile"] == 1 ? true : false,
|
|
||||||
isTablet: element["isTablet"] == 1 ? true : false,
|
|
||||||
isOffline: element["isOffline"] == 1 ? true : false
|
|
||||||
));
|
|
||||||
break;
|
break;
|
||||||
case DatabaseTableType.sections:
|
case DatabaseTableType.sections:
|
||||||
print("RESUUUUUUUULT");
|
dataToReturn.add(getSectionFromDB(element));
|
||||||
print(element['title']);
|
|
||||||
print(json.decode(element['title']));
|
|
||||||
print(List<TranslationDTO>.from(element["title"]));
|
|
||||||
dataToReturn.add(SectionDTO(
|
|
||||||
id: element["id"],
|
|
||||||
label: element["label"],
|
|
||||||
title: element['title'].map<TranslationDTO>((q) => TranslationDTO.fromJson(q)).toList(),
|
|
||||||
description: json.decode(element['description']).map<TranslationDTO>((q) => TranslationDTO.fromJson(q)).toList(),
|
|
||||||
imageId: element["imageId"],
|
|
||||||
imageSource: element["imageSource"],
|
|
||||||
configurationId: element["configurationId"],
|
|
||||||
type: element["type"], // TODO
|
|
||||||
data: element["data"], // TODO
|
|
||||||
dateCreation: DateTime.tryParse(element["dateCreation"]),
|
|
||||||
order: element["orderOfElement"],
|
|
||||||
));
|
|
||||||
print("RESUUUUUUUULT");
|
|
||||||
break;
|
break;
|
||||||
case DatabaseTableType.resources:
|
case DatabaseTableType.resources:
|
||||||
dataToReturn.add(ResourceDTO(
|
dataToReturn.add(getResourceFromDB(element));
|
||||||
id: element["id"],
|
|
||||||
label: element["label"],
|
|
||||||
data: element["data"], // TODO
|
|
||||||
type: element["type"] // TODO
|
|
||||||
));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
print(error);
|
print(error);
|
||||||
});
|
});
|
||||||
print(dataToReturn);
|
|
||||||
return dataToReturn;
|
return dataToReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,4 +223,44 @@ class DatabaseHelper {
|
|||||||
return resourcesTable;
|
return resourcesTable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigurationDTO getConfigurationFromDB(dynamic element) {
|
||||||
|
return ConfigurationDTO(
|
||||||
|
id: element["id"],
|
||||||
|
label: element["label"],
|
||||||
|
primaryColor: element["primaryColor"],
|
||||||
|
secondaryColor: element["secondaryColor"],
|
||||||
|
languages: List<String>.from(jsonDecode(element["languages"])),
|
||||||
|
dateCreation: DateTime.tryParse(element["dateCreation"]),
|
||||||
|
isMobile: element["isMobile"] == 1 ? true : false,
|
||||||
|
isTablet: element["isTablet"] == 1 ? true : false,
|
||||||
|
isOffline: element["isOffline"] == 1 ? true : false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SectionDTO getSectionFromDB(dynamic element) {
|
||||||
|
var titles = List<TranslationDTO>.from(json.decode(element['title']).map<dynamic>((q) => TranslationDTO.fromJson(q)).toList());
|
||||||
|
var descriptions = List<TranslationDTO>.from(json.decode(element['description']).map<dynamic>((q) => TranslationDTO.fromJson(q)).toList());
|
||||||
|
return SectionDTO(
|
||||||
|
id: element["id"],
|
||||||
|
label: element["label"],
|
||||||
|
title: titles,
|
||||||
|
description: descriptions,
|
||||||
|
imageId: element["imageId"],
|
||||||
|
imageSource: element["imageSource"],
|
||||||
|
configurationId: element["configurationId"],
|
||||||
|
type: SectionType.values[element["type"]],
|
||||||
|
data: element["data"],
|
||||||
|
dateCreation: DateTime.tryParse(element["dateCreation"]),
|
||||||
|
order: int.parse(element["orderOfElement"]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceModel getResourceFromDB(dynamic element) {
|
||||||
|
return ResourceModel(
|
||||||
|
id: element["id"],
|
||||||
|
data: element["data"],
|
||||||
|
type: ResourceType.values[element["type"]]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
12
lib/Helpers/translationHelper.dart
Normal file
12
lib/Helpers/translationHelper.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'package:manager_api/api.dart';
|
||||||
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
|
|
||||||
|
class TranslationHelper {
|
||||||
|
static String get(List<TranslationDTO>? translationDTO, AppContext appContext) {
|
||||||
|
try {
|
||||||
|
return translationDTO!.where((element) => element.language == appContext.getContext().language).first.value!;
|
||||||
|
} catch (_) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
lib/Models/resourceModel.dart
Normal file
31
lib/Models/resourceModel.dart
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:manager_api/api.dart';
|
||||||
|
|
||||||
|
class ResourceModel {
|
||||||
|
String? id = "";
|
||||||
|
String? data = "";
|
||||||
|
ResourceType? type;
|
||||||
|
|
||||||
|
ResourceModel({this.id, this.data, this.type});
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'data': data,
|
||||||
|
'type': type!.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory ResourceModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return ResourceModel(
|
||||||
|
id: json['id'] as String,
|
||||||
|
data: json['data'] as String,
|
||||||
|
type: json['type'] as ResourceType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ResourceModel{id: $id, type: $type, data: $data}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,20 @@
|
|||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:manager_api/api.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Helpers/networkCheck.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Models/resourceModel.dart';
|
||||||
import 'package:mymuseum_visitapp/Screens/Scanner/scanner_old.dart';
|
import 'package:mymuseum_visitapp/Screens/Scanner/scanner_old.dart';
|
||||||
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
|
import 'package:mymuseum_visitapp/client.dart';
|
||||||
import 'package:mymuseum_visitapp/constants.dart';
|
import 'package:mymuseum_visitapp/constants.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class ArticlePage extends StatefulWidget {
|
class ArticlePage extends StatefulWidget {
|
||||||
const ArticlePage({Key? key, required this.articleId}) : super(key: key);
|
const ArticlePage({Key? key, required this.articleId}) : super(key: key);
|
||||||
@ -15,27 +26,70 @@ class ArticlePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ArticlePageState extends State<ArticlePage> {
|
class _ArticlePageState extends State<ArticlePage> {
|
||||||
|
SectionDTO? sectionDTO;
|
||||||
|
ArticleDTO? articleDTO;
|
||||||
|
ResourceModel? resourceModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final appContext = Provider.of<AppContext>(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: CustomAppBar(
|
appBar: CustomAppBar(
|
||||||
title: "ArticlePage",
|
title: "ArticlePage",
|
||||||
isHomeButton: false,
|
isHomeButton: false,
|
||||||
),
|
),
|
||||||
body: Center(
|
body: FutureBuilder(
|
||||||
|
future: getArticle(appContext.clientAPI, widget.articleId),
|
||||||
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
|
if(articleDTO != null && sectionDTO != null) {
|
||||||
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(widget.articleId),
|
Text(TranslationHelper.get(sectionDTO!.title, appContext)),
|
||||||
Text(
|
Text(
|
||||||
'coucou',
|
TranslationHelper.get(articleDTO!.content, appContext),
|
||||||
style: Theme.of(context).textTheme.headline4,
|
style: Theme.of(context).textTheme.headline4,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
|
resourceModel != null ? Image.memory(base64Decode(resourceModel!.data!)) : const Text("image"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return const Loading();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
),
|
),
|
||||||
floatingActionButton: const ScannerBouton(isReplacement: true),
|
floatingActionButton: const ScannerBouton(isReplacement: true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<ArticleDTO?> getArticle(Client client, String articleId) async {
|
||||||
|
try {
|
||||||
|
bool isOnline = await hasNetwork();
|
||||||
|
if(true) {
|
||||||
|
await DatabaseHelper.instance.queryWithId(DatabaseTableType.sections, articleId).then((value) async {
|
||||||
|
sectionDTO = DatabaseHelper.instance.getSectionFromDB(value.first);
|
||||||
|
if(sectionDTO!.type == SectionType.Article) {
|
||||||
|
articleDTO = ArticleDTO.fromJson(jsonDecode(sectionDTO!.data!));
|
||||||
|
if(articleDTO!.images!.isNotEmpty) {
|
||||||
|
await DatabaseHelper.instance.queryWithId(DatabaseTableType.resources, articleDTO!.images!.first.resourceId!).then((value) {
|
||||||
|
resourceModel = DatabaseHelper.instance.getResourceFromDB(value.first);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// TODO ONLINE
|
||||||
|
return null; // TODO return local list..
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
print("IN CATCH");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:auto_size_text/auto_size_text.dart';
|
import 'package:auto_size_text/auto_size_text.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:manager_api/api.dart';
|
import 'package:manager_api/api.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/networkCheck.dart';
|
import 'package:mymuseum_visitapp/Helpers/networkCheck.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Models/resourceModel.dart';
|
||||||
import 'package:mymuseum_visitapp/Screens/Visit/visit.dart';
|
import 'package:mymuseum_visitapp/Screens/Visit/visit.dart';
|
||||||
import 'package:mymuseum_visitapp/app_context.dart';
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
import 'package:mymuseum_visitapp/client.dart';
|
import 'package:mymuseum_visitapp/client.dart';
|
||||||
@ -162,8 +163,6 @@ class _HomePageState extends State<HomePage> {
|
|||||||
bool isOnline = await hasNetwork();
|
bool isOnline = await hasNetwork();
|
||||||
if(isOnline) {
|
if(isOnline) {
|
||||||
List<SectionDTO>? sections = await client.sectionApi!.sectionGetFromConfiguration(configurationId);
|
List<SectionDTO>? sections = await client.sectionApi!.sectionGetFromConfiguration(configurationId);
|
||||||
print(sections);
|
|
||||||
|
|
||||||
return sections;
|
return sections;
|
||||||
} else {
|
} else {
|
||||||
return []; // TODO return local list..
|
return []; // TODO return local list..
|
||||||
@ -175,32 +174,72 @@ class _HomePageState extends State<HomePage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> getAndDownloadImage(Client client, ImageDTO imageDTO) async {
|
||||||
|
try {
|
||||||
|
bool isOnline = await hasNetwork();
|
||||||
|
if(isOnline) {
|
||||||
|
var source = imageDTO.source_;
|
||||||
|
if(imageDTO.source_!.contains("localhost:5000")) {
|
||||||
|
source = imageDTO.source_!.replaceAll("http://localhost:5000", client.apiApi!.basePath);
|
||||||
|
}
|
||||||
|
HttpClient client2 = HttpClient();
|
||||||
|
var _downloadData = <int>[];
|
||||||
|
client2.getUrl(Uri.parse(source!))
|
||||||
|
.then((HttpClientRequest request) {
|
||||||
|
return request.close();
|
||||||
|
})
|
||||||
|
.then((HttpClientResponse response) {
|
||||||
|
response.listen((d) => _downloadData.addAll(d),
|
||||||
|
onDone: () async {
|
||||||
|
final base64Str = base64.encode(_downloadData);
|
||||||
|
ResourceModel resourceModel = ResourceModel(id: imageDTO.resourceId, data: base64Str, type: ResourceType.Image);
|
||||||
|
await DatabaseHelper.instance.insert(DatabaseTableType.resources, resourceModel.toMap());
|
||||||
|
//var test = base64.decode(base64Str);
|
||||||
|
//return base64Str;
|
||||||
|
/*setState(() {
|
||||||
|
base64TEST = base64Str;
|
||||||
|
});*/
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
//return file;
|
||||||
|
} else {
|
||||||
|
//return null; // TODO return local list..
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
print("IN CATCH");
|
||||||
|
//return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> downloadClicked(AppContext appContext, ConfigurationDTO configuration) async {
|
Future<void> downloadClicked(AppContext appContext, ConfigurationDTO configuration) async {
|
||||||
// Display config only downloaded - TODO
|
// Display config only downloaded - TODO
|
||||||
|
|
||||||
// Update local DB - Configuration
|
// Update local DB - Configuration
|
||||||
await DatabaseHelper.instance.insert(DatabaseTableType.configurations, configuration.toJson());
|
await DatabaseHelper.instance.insert(DatabaseTableType.configurations, configuration.toJson());
|
||||||
|
|
||||||
var teeest = await DatabaseHelper.instance.getData(DatabaseTableType.configurations);
|
//var teeest = await DatabaseHelper.instance.getData(DatabaseTableType.configurations);
|
||||||
print("RESULT new or update config");
|
|
||||||
print(teeest);
|
|
||||||
|
|
||||||
print("TODO download");
|
|
||||||
List<SectionDTO>? sections = await getAllSections(appContext.clientAPI, configuration.id!);
|
List<SectionDTO>? sections = await getAllSections(appContext.clientAPI, configuration.id!);
|
||||||
|
|
||||||
if(sections!.isNotEmpty) {
|
if(sections!.isNotEmpty) {
|
||||||
// Update local DB - Sections
|
// Update local DB - Sections
|
||||||
for(var section in sections) {
|
for(var section in sections) {
|
||||||
print("Section to store == ");
|
|
||||||
print(section.toJson());
|
|
||||||
print(section.type == SectionType.Quizz);
|
|
||||||
|
|
||||||
var test = sectionToMap(section);
|
|
||||||
print("SECTION TOOOOO MAAAAAAAAAAAAAAAAAAAAP");
|
|
||||||
print(test);
|
|
||||||
|
|
||||||
|
|
||||||
await DatabaseHelper.instance.insert(DatabaseTableType.sections, sectionToMap(section));
|
await DatabaseHelper.instance.insert(DatabaseTableType.sections, sectionToMap(section));
|
||||||
|
// TODO handle other type of section
|
||||||
|
if(section.type == SectionType.Article) {
|
||||||
|
// Download all images..
|
||||||
|
ArticleDTO? articleDTO = ArticleDTO.fromJson(jsonDecode(section.data!));
|
||||||
|
|
||||||
|
if(articleDTO != null) {
|
||||||
|
for(var image in articleDTO!.images!) {
|
||||||
|
await getAndDownloadImage(appContext.clientAPI, image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +256,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
'configurationId': section.configurationId,
|
'configurationId': section.configurationId,
|
||||||
'isSubSection': section.isSubSection,
|
'isSubSection': section.isSubSection,
|
||||||
'parentId': section.parentId,
|
'parentId': section.parentId,
|
||||||
'type': section.type!.toJson(),
|
'type': section.type!.value,
|
||||||
'data': section.data,
|
'data': section.data,
|
||||||
'dateCreation': section.dateCreation!.toUtc().toIso8601String(),
|
'dateCreation': section.dateCreation!.toUtc().toIso8601String(),
|
||||||
'orderOfElement': section.order,
|
'orderOfElement': section.order,
|
||||||
|
|||||||
@ -23,17 +23,17 @@ class ResourceType {
|
|||||||
|
|
||||||
int toJson() => value;
|
int toJson() => value;
|
||||||
|
|
||||||
static const number0 = ResourceType._(0);
|
static const Image = ResourceType._(0);
|
||||||
static const number1 = ResourceType._(1);
|
static const Video = ResourceType._(1);
|
||||||
static const number2 = ResourceType._(2);
|
static const ImageUrl = ResourceType._(2);
|
||||||
static const number3 = ResourceType._(3);
|
static const VideoUrl = ResourceType._(3);
|
||||||
|
|
||||||
/// List of all possible values in this [enum][ResourceType].
|
/// List of all possible values in this [enum][ResourceType].
|
||||||
static const values = <ResourceType>[
|
static const values = <ResourceType>[
|
||||||
number0,
|
Image,
|
||||||
number1,
|
Video,
|
||||||
number2,
|
ImageUrl,
|
||||||
number3,
|
VideoUrl
|
||||||
];
|
];
|
||||||
|
|
||||||
static ResourceType? fromJson(dynamic value) => ResourceTypeTypeTransformer().decode(value);
|
static ResourceType? fromJson(dynamic value) => ResourceTypeTypeTransformer().decode(value);
|
||||||
@ -72,10 +72,10 @@ class ResourceTypeTypeTransformer {
|
|||||||
ResourceType? decode(dynamic data, {bool allowNull = true}) {
|
ResourceType? decode(dynamic data, {bool allowNull = true}) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case 0: return ResourceType.number0;
|
case "Image": return ResourceType.Image;
|
||||||
case 1: return ResourceType.number1;
|
case "Video": return ResourceType.Video;
|
||||||
case 2: return ResourceType.number2;
|
case "ImageUrl": return ResourceType.ImageUrl;
|
||||||
case 3: return ResourceType.number3;
|
case "VideoUrl": return ResourceType.VideoUrl;
|
||||||
default:
|
default:
|
||||||
if (!allowNull) {
|
if (!allowNull) {
|
||||||
throw ArgumentError('Unknown enum value to decode: $data');
|
throw ArgumentError('Unknown enum value to decode: $data');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user