backup.
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import '../../widgets/general/text_link.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../generated/l10n.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../../utils/extensions.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
import '../../constants.dart';
|
||||
import '../../utils/util_web.dart' if (dart.library.io) '../../utils/util_io.dart';
|
||||
|
||||
class DownloadItem extends StatefulWidget {
|
||||
@@ -16,15 +24,20 @@ class DownloadItem extends StatefulWidget {
|
||||
}
|
||||
|
||||
class DownloadItemState extends State<DownloadItem> {
|
||||
final double buttonWidth = 114.0;
|
||||
final double iconWidth = 48.0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return Container(
|
||||
width: widget.width ?? MediaQuery.of(context).size.width,
|
||||
padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 10.0, right: 10.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -32,15 +45,26 @@ class DownloadItemState extends State<DownloadItem> {
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
child: Util.showImage(
|
||||
'https:${widget.desc['app_icon']}',
|
||||
width: 32.0,
|
||||
height: 32.0,
|
||||
fit: BoxFit.fill,
|
||||
child: (kIsWeb) ?
|
||||
Image.network(
|
||||
'${widget.desc['app_icon']}',
|
||||
) :
|
||||
SvgPicture.network(
|
||||
'${widget.desc['app_icon']}',
|
||||
placeholderBuilder: (BuildContext context) => Container(
|
||||
padding: const EdgeInsets.all(30.0),
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
width: iconWidth,
|
||||
height: iconWidth,
|
||||
margin: EdgeInsets.only(right: 16.0),
|
||||
),
|
||||
Container(
|
||||
width: widget.width != null ? widget.width - iconWidth - buttonWidth - 60 : MediaQuery.of(context).size.width - iconWidth - buttonWidth - 60,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${widget.desc['name']}',
|
||||
@@ -49,6 +73,8 @@ class DownloadItemState extends State<DownloadItem> {
|
||||
fontSize: 15.0,
|
||||
color: Colors.black87,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
'${widget.desc['version']}',
|
||||
@@ -57,6 +83,7 @@ class DownloadItemState extends State<DownloadItem> {
|
||||
color: Colors.black38,
|
||||
),
|
||||
),
|
||||
getSupportedOSs(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -64,18 +91,19 @@ class DownloadItemState extends State<DownloadItem> {
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: buttonWidth,
|
||||
child: getDownloadButton(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
|
||||
child: Text(
|
||||
'${widget.desc['description']}',
|
||||
style: TextStyle(
|
||||
color: Colors.black54,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -83,8 +111,222 @@ class DownloadItemState extends State<DownloadItem> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget getDownloadButton() {
|
||||
Widget getSupportedOSs() {
|
||||
Row row = Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [],
|
||||
);
|
||||
for (int i = 0; i < (widget.desc['urls'] as List).length; i++) {
|
||||
switch((widget.desc['urls'] as List)[i]['os']) {
|
||||
case 'windows':
|
||||
row.children.add(Container(
|
||||
margin: EdgeInsets.all(3.0),
|
||||
child: Icon(
|
||||
IconData(
|
||||
Constants.FONT_WINDOWS,
|
||||
fontFamily: 'wisetronic',
|
||||
fontPackage: null
|
||||
),
|
||||
color: Colors.green,
|
||||
size: 20.0,
|
||||
),
|
||||
));
|
||||
break;
|
||||
case 'mac':
|
||||
row.children.add(Container(
|
||||
margin: EdgeInsets.all(3.0),
|
||||
child: Icon(
|
||||
IconData(
|
||||
Constants.FONT_APPLE,
|
||||
fontFamily: 'wisetronic',
|
||||
fontPackage: null
|
||||
),
|
||||
color: Colors.green,
|
||||
size: 20.0,
|
||||
),
|
||||
));
|
||||
break;
|
||||
case 'ubuntu':
|
||||
row.children.add(Container(
|
||||
margin: EdgeInsets.all(3.0),
|
||||
child: Icon(
|
||||
IconData(
|
||||
Constants.FONT_UBUNTU,
|
||||
fontFamily: 'wisetronic',
|
||||
fontPackage: null
|
||||
),
|
||||
color: Colors.green,
|
||||
size: 20.0,
|
||||
),
|
||||
));
|
||||
break;
|
||||
case 'android':
|
||||
row.children.add(Container(
|
||||
margin: EdgeInsets.all(3.0),
|
||||
child: Icon(
|
||||
IconData(
|
||||
Constants.FONT_ANDROID,
|
||||
fontFamily: 'wisetronic',
|
||||
fontPackage: null
|
||||
),
|
||||
color: Colors.green,
|
||||
size: 20.0,
|
||||
),
|
||||
));
|
||||
break;
|
||||
case 'ios':
|
||||
row.children.add(Container(
|
||||
margin: EdgeInsets.all(3.0),
|
||||
child: Icon(
|
||||
IconData(
|
||||
Constants.FONT_IOS,
|
||||
fontFamily: 'wisetronic',
|
||||
fontPackage: null
|
||||
),
|
||||
color: Colors.green,
|
||||
size: 20.0,
|
||||
),
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
return null;
|
||||
Widget getDownloadButton() {
|
||||
String downloadUrl;
|
||||
String os = Utils.getOs();
|
||||
String selectedOs;
|
||||
List<String> supportedOss = [];
|
||||
for (int i = 0; i < (widget.desc['urls'] as List).length; i++) {
|
||||
supportedOss.add((widget.desc['urls'] as List)[i]['os']);
|
||||
if ((widget.desc['urls'] as List)[i]['url'] == 'instore') {
|
||||
downloadUrl = 'instore';
|
||||
}
|
||||
if ((widget.desc['urls'] as List)[i]['os'] == os) {
|
||||
selectedOs = (widget.desc['urls'] as List)[i]['os'];
|
||||
downloadUrl = (widget.desc['urls'] as List)[i]['url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
print('download url $downloadUrl');
|
||||
if (downloadUrl != null && downloadUrl == 'instore') {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
S.of(context).install_in_store,
|
||||
style: TextStyle(
|
||||
color: Colors.black54,
|
||||
fontSize: 11.5,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
// color: Colors.black54,
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
bottom: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
left: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
right: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(5.0),
|
||||
topRight: Radius.circular(5.0),
|
||||
bottomLeft: Radius.circular(5.0),
|
||||
bottomRight: Radius.circular(5.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (downloadUrl != null && downloadUrl.isNotEmpty) {
|
||||
return RaisedButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(right: 0.0, left: 6.0, top: 6.0, bottom: 6.0),
|
||||
child: Icon(
|
||||
IconData(
|
||||
Utils.getOsFontHex(selectedOs),
|
||||
fontFamily: 'wisetronic',
|
||||
fontPackage: null
|
||||
),
|
||||
color: Colors.white,
|
||||
size: 18.0,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
S.of(context).download,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () async {
|
||||
if (await canLaunch(downloadUrl)) {
|
||||
await launch('$downloadUrl');
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
S.of(context).download_with_token(supportedOss.join(', ').eachFirstCap),
|
||||
style: TextStyle(
|
||||
color: Colors.black54,
|
||||
fontSize: 11.5,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
// color: Colors.black54,
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
bottom: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
left: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
right: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black54,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(5.0),
|
||||
topRight: Radius.circular(5.0),
|
||||
bottomLeft: Radius.circular(5.0),
|
||||
bottomRight: Radius.circular(5.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user