Finetune download prompt
This commit is contained in:
parent
0637a47e56
commit
91ec09fcb9
@ -20,9 +20,13 @@ import 'package:mymuseum_visitapp/app_context.dart';
|
|||||||
import 'package:mymuseum_visitapp/constants.dart';
|
import 'package:mymuseum_visitapp/constants.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationsList extends StatefulWidget {
|
class ConfigurationsList extends StatefulWidget {
|
||||||
const ConfigurationsList({Key? key, required this.configurations, required this.alreadyDownloaded, required this.requestRefresh}) : super(key: key);
|
const ConfigurationsList(
|
||||||
|
{Key? key,
|
||||||
|
required this.configurations,
|
||||||
|
required this.alreadyDownloaded,
|
||||||
|
required this.requestRefresh})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
final List<ConfigurationDTO> configurations;
|
final List<ConfigurationDTO> configurations;
|
||||||
final List<String?> alreadyDownloaded;
|
final List<String?> alreadyDownloaded;
|
||||||
@ -46,22 +50,28 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
visitAppContext = appContext.getContext();
|
visitAppContext = appContext.getContext();
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
shrinkWrap: true, //I've set this as true here depending on what your listview content is
|
shrinkWrap:
|
||||||
|
true, //I've set this as true here depending on what your listview content is
|
||||||
//physics: NeverScrollableScrollPhysics(),//This prevents scrolling, but may inhibit refresh indicator, remove as you need
|
//physics: NeverScrollableScrollPhysics(),//This prevents scrolling, but may inhibit refresh indicator, remove as you need
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
if(configurations[index].isOffline! && alreadyDownloaded.any((c) => c == configurations[index].id)) {
|
if (configurations[index].isOffline! &&
|
||||||
if(!configurations[index].languages!.contains(visitAppContext.language)) {
|
alreadyDownloaded.any((c) => c == configurations[index].id)) {
|
||||||
|
if (!configurations[index]
|
||||||
|
.languages!
|
||||||
|
.contains(visitAppContext.language)) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text(TranslationHelper.getFromLocale("languageNotSupported", appContext.getContext())), backgroundColor: kBlue2),
|
SnackBar(
|
||||||
|
content: Text(TranslationHelper.getFromLocale(
|
||||||
|
"languageNotSupported", appContext.getContext())),
|
||||||
|
backgroundColor: kBlue2),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Update context
|
// Update context
|
||||||
@ -71,7 +81,8 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
appContext.setContext(visitAppContext);
|
appContext.setContext(visitAppContext);
|
||||||
|
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||||
builder: (context) => VisitPage(configurationId: configurations[index].id!),
|
builder: (context) =>
|
||||||
|
VisitPage(configurationId: configurations[index].id!),
|
||||||
));
|
));
|
||||||
/*Navigator.push(
|
/*Navigator.push(
|
||||||
context,
|
context,
|
||||||
@ -82,10 +93,13 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
/**/
|
/**/
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(configurations[index].isOffline!) {
|
if (configurations[index].isOffline!) {
|
||||||
// Not already downloaded
|
// Not already downloaded
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text(TranslationHelper.getFromLocale("visitDownloadWarning", appContext.getContext())), backgroundColor: kBlue2),
|
SnackBar(
|
||||||
|
content: Text(TranslationHelper.getFromLocale(
|
||||||
|
"visitDownloadWarning", appContext.getContext())),
|
||||||
|
backgroundColor: kBlue2),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Online mode
|
// Online mode
|
||||||
@ -101,77 +115,99 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
);*/
|
);*/
|
||||||
|
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||||
builder: (context) => VisitPage(configurationId: configurations[index].id!),
|
builder: (context) =>
|
||||||
|
VisitPage(configurationId: configurations[index].id!),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: size.height*0.15,
|
height: size.height * 0.15,
|
||||||
decoration: boxDecoration(configurations[index], false),
|
decoration: boxDecoration(configurations[index], false),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
if(configurations[index].imageId != null)
|
if (configurations[index].imageId != null)
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0),
|
padding: const EdgeInsets.symmetric(horizontal: 0),
|
||||||
height: 136,
|
height: 136,
|
||||||
// image is square but we add extra 20 + 20 padding thats why width is 200
|
// image is square but we add extra 20 + 20 padding thats why width is 200
|
||||||
width: size.width*0.3,
|
width: size.width * 0.3,
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: ApiService.getResource(appContext, configurations[index].imageId!),
|
future: ApiService.getResource(
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
appContext, configurations[index].imageId!),
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
builder:
|
||||||
return snapshot.data != null ? ClipRRect(
|
(context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), bottomLeft: Radius.circular(20)),
|
if (snapshot.connectionState ==
|
||||||
child: snapshot.data.data != null ? Image.memory(
|
ConnectionState.done) {
|
||||||
base64Decode(snapshot.data.data!),
|
return snapshot.data != null
|
||||||
fit: BoxFit.cover
|
? ClipRRect(
|
||||||
) : Image.network(
|
borderRadius: const BorderRadius.only(
|
||||||
configurations[index].imageSource!,
|
topLeft: Radius.circular(20),
|
||||||
fit: BoxFit.cover,
|
bottomLeft: Radius.circular(20)),
|
||||||
loadingBuilder: (BuildContext context, Widget child,
|
child: snapshot.data.data != null
|
||||||
ImageChunkEvent? loadingProgress) {
|
? Image.memory(
|
||||||
if (loadingProgress == null) {
|
base64Decode(
|
||||||
return child;
|
snapshot.data.data!),
|
||||||
}
|
fit: BoxFit.cover)
|
||||||
return Center(
|
: Image.network(
|
||||||
child: CircularProgressIndicator(
|
configurations[index]
|
||||||
color: kBlue1,
|
.imageSource!,
|
||||||
value: loadingProgress.expectedTotalBytes != null
|
fit: BoxFit.cover,
|
||||||
? loadingProgress.cumulativeBytesLoaded /
|
loadingBuilder:
|
||||||
loadingProgress.expectedTotalBytes!
|
(BuildContext context,
|
||||||
: null,
|
Widget child,
|
||||||
),
|
ImageChunkEvent?
|
||||||
);
|
loadingProgress) {
|
||||||
},
|
if (loadingProgress ==
|
||||||
),
|
null) {
|
||||||
) : const Text("");
|
return child;
|
||||||
} else if (snapshot.connectionState == ConnectionState.none) {
|
}
|
||||||
return Text(TranslationHelper.getFromLocale("noData", appContext.getContext()));
|
return Center(
|
||||||
|
child:
|
||||||
|
CircularProgressIndicator(
|
||||||
|
color: kBlue1,
|
||||||
|
value: loadingProgress
|
||||||
|
.expectedTotalBytes !=
|
||||||
|
null
|
||||||
|
? loadingProgress
|
||||||
|
.cumulativeBytesLoaded /
|
||||||
|
loadingProgress
|
||||||
|
.expectedTotalBytes!
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Text("");
|
||||||
|
} else if (snapshot.connectionState ==
|
||||||
|
ConnectionState.none) {
|
||||||
|
return Text(TranslationHelper.getFromLocale(
|
||||||
|
"noData", appContext.getContext()));
|
||||||
} else {
|
} else {
|
||||||
return Center(
|
return Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: size.height * 0.15,
|
height: size.height * 0.15,
|
||||||
child: const Loading()
|
child: const Loading()));
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: size.width*0.45,
|
width: size.width * 0.45,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(left: 10),
|
padding: const EdgeInsets.only(left: 10),
|
||||||
child: AutoSizeText(
|
child: AutoSizeText(
|
||||||
TranslationHelper.get(configurations[index].title, appContext.getContext()),
|
TranslationHelper.get(
|
||||||
style: const TextStyle(fontSize: kMenuTitleDetailSize),
|
configurations[index].title,
|
||||||
|
appContext.getContext()),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: kMenuTitleDetailSize),
|
||||||
maxFontSize: 18,
|
maxFontSize: 18,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
),
|
),
|
||||||
@ -181,7 +217,7 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if(configurations[index].isOffline!)
|
if (configurations[index].isOffline!)
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
@ -196,24 +232,29 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
margin: const EdgeInsets.all(8),
|
margin: const EdgeInsets.all(8),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await downloadClicked(appContext, configurations[index]);
|
await downloadClicked(
|
||||||
|
appContext, configurations[index]);
|
||||||
widget.requestRefresh();
|
widget.requestRefresh();
|
||||||
},
|
},
|
||||||
child: configurations[index].isOffline! && !alreadyDownloaded.any((c) => c == configurations[index].id) ?
|
child: configurations[index].isOffline! &&
|
||||||
const Icon(Icons.download, color: Colors.white) : const Icon(Icons.refresh, color: Colors.white),
|
!alreadyDownloaded.any(
|
||||||
|
(c) => c == configurations[index].id)
|
||||||
|
? const Icon(Icons.download,
|
||||||
|
color: Colors.white)
|
||||||
|
: const Icon(Icons.refresh,
|
||||||
|
color: Colors.white),
|
||||||
),
|
),
|
||||||
)
|
))
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
itemCount: configurations.length
|
itemCount: configurations.length);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> downloadClicked(AppContext appContext, ConfigurationDTO configuration) async {
|
Future<void> downloadClicked(
|
||||||
|
AppContext appContext, ConfigurationDTO configuration) async {
|
||||||
bool isCancel = false;
|
bool isCancel = false;
|
||||||
//if(!alreadyDownloaded.any((c) => c == configuration.id)) {
|
//if(!alreadyDownloaded.any((c) => c == configuration.id)) {
|
||||||
await showDialog(
|
await showDialog(
|
||||||
@ -226,9 +267,28 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(!alreadyDownloaded.any((c) => c == configuration.id) ? TranslationHelper.getFromLocale("downloadPrompt", appContext.getContext()) : TranslationHelper.getFromLocale("downloadPromptUpdate", appContext.getContext()), style: TextStyle(color: kMainColor)),
|
Padding(
|
||||||
Text(TranslationHelper.getFromLocale("downloadLanguage", appContext.getContext()), style: TextStyle(color: kMainColor)),
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
!alreadyDownloaded.any((c) => c == configuration.id)
|
||||||
|
? TranslationHelper.getFromLocale(
|
||||||
|
"downloadPrompt", appContext.getContext())
|
||||||
|
: TranslationHelper.getFromLocale(
|
||||||
|
"downloadPromptUpdate",
|
||||||
|
appContext.getContext()),
|
||||||
|
style: TextStyle(color: kMainColor),
|
||||||
|
textAlign: TextAlign.center),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 15,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
TranslationHelper.getFromLocale(
|
||||||
|
"downloadLanguage", appContext.getContext()),
|
||||||
|
style: TextStyle(color: kMainColor),
|
||||||
|
textAlign: TextAlign.center),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 25,
|
height: 25,
|
||||||
),
|
),
|
||||||
@ -238,14 +298,20 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(TranslationHelper.getFromLocale("close", appContext.getContext()), style: TextStyle(color: kMainColor)),
|
child: Text(
|
||||||
|
TranslationHelper.getFromLocale(
|
||||||
|
"close", appContext.getContext()),
|
||||||
|
style: TextStyle(color: kMainColor)),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
isCancel = true;
|
isCancel = true;
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(TranslationHelper.getFromLocale("download", appContext.getContext()), style: TextStyle(color: kMainColor)),
|
child: Text(
|
||||||
|
TranslationHelper.getFromLocale(
|
||||||
|
"download", appContext.getContext()),
|
||||||
|
style: TextStyle(color: kMainColor)),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
@ -257,8 +323,9 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
});
|
});
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if(!isCancel) {
|
if (!isCancel) {
|
||||||
String loadingText = TranslationHelper.getFromLocale("downloadConfiguration", appContext.getContext());
|
String loadingText = TranslationHelper.getFromLocale(
|
||||||
|
"downloadConfiguration", appContext.getContext());
|
||||||
showDialog(
|
showDialog(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
context: context,
|
context: context,
|
||||||
@ -281,7 +348,8 @@ class _ConfigurationsListState extends State<ConfigurationsList> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
var isFinish = await DownloadConfiguration.download(appContext, configuration);
|
var isFinish =
|
||||||
|
await DownloadConfiguration.download(appContext, configuration);
|
||||||
print("C4EST FINIITO");
|
print("C4EST FINIITO");
|
||||||
print(isFinish);
|
print(isFinish);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user