|
|
|
@ -1,10 +1,15 @@
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:ellipsized_text/ellipsized_text.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:open_file/open_file.dart';
|
|
|
|
import 'package:open_file/open_file.dart';
|
|
|
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
|
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
import 'package:test_sa/views/widgets/buttons/app_back_button.dart';
|
|
|
|
import 'package:test_sa/views/widgets/buttons/app_back_button.dart';
|
|
|
|
import 'package:test_sa/views/widgets/loaders/image_loader.dart';
|
|
|
|
import 'package:test_sa/views/widgets/loaders/image_loader.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
@ -12,78 +17,180 @@ import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class FilesList extends StatelessWidget {
|
|
|
|
class FilesList extends StatelessWidget {
|
|
|
|
final List<String> images;
|
|
|
|
final List<String> images;
|
|
|
|
final EdgeInsets? padding;
|
|
|
|
final EdgeInsets? padding;
|
|
|
|
|
|
|
|
final bool showAsListView;
|
|
|
|
|
|
|
|
|
|
|
|
const FilesList({Key? key, this.images = const <String>[], this.padding}) : super(key: key);
|
|
|
|
const FilesList({Key? key, this.images = const <String>[], this.padding, this.showAsListView = false}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GridView.builder(
|
|
|
|
return showAsListView
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
|
|
|
? ListView.separated(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
shrinkWrap: true,
|
|
|
|
shrinkWrap: true,
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6, mainAxisSpacing: 8, crossAxisSpacing: 8),
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
itemCount: images.length,
|
|
|
|
itemBuilder: (cxt, itemIndex) {
|
|
|
|
itemBuilder: (context, itemIndex) {
|
|
|
|
if (!images[itemIndex].contains(".")) {
|
|
|
|
if (!images[itemIndex].contains(".")) {
|
|
|
|
return const Text("Bad\nFile");
|
|
|
|
return const Text("Bad\nFile");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var isImage =
|
|
|
|
var isImage = images[itemIndex].split(".").last.toLowerCase() == "png" || images[itemIndex].split(".").last.toLowerCase() == "jpg" || images[itemIndex].split(".").last.toLowerCase() == "jpeg";
|
|
|
|
images[itemIndex].split(".").last.toLowerCase() == "png" || images[itemIndex].split(".").last.toLowerCase() == "jpg" || images[itemIndex].split(".").last.toLowerCase() == "jpeg";
|
|
|
|
var isPdf = images[itemIndex].split(".").last.toLowerCase() == "pdf";
|
|
|
|
var isPdf = images[itemIndex].split(".").last.toLowerCase() == "pdf";
|
|
|
|
var isExcel = images[itemIndex].split(".").last.toLowerCase() == "xlsx";
|
|
|
|
var isExcel = images[itemIndex].split(".").last.toLowerCase() == "xlsx";
|
|
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
return Row(
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
children: [
|
|
|
|
color: Colors.white,
|
|
|
|
Container(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
width: 48.toScreenWidth,
|
|
|
|
side: const BorderSide(width: 1, color: Color(0xFFEAF1F4)),
|
|
|
|
height: 48.toScreenWidth,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
),
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
child: ClipRRect(
|
|
|
|
side: const BorderSide(width: 1, color: Color(0xFFEAF1F4)),
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
child: (isImage
|
|
|
|
),
|
|
|
|
? (_isLocalUrl(images[itemIndex])
|
|
|
|
),
|
|
|
|
? Image.file(File(images[itemIndex]))
|
|
|
|
child: ClipRRect(
|
|
|
|
: ImageLoader(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
url: images[itemIndex],
|
|
|
|
child: (isImage
|
|
|
|
boxFit: BoxFit.cover,
|
|
|
|
? (_isLocalUrl(images[itemIndex])
|
|
|
|
height: 48,
|
|
|
|
? Image.file(File(images[itemIndex]))
|
|
|
|
width: 48,
|
|
|
|
: ImageLoader(
|
|
|
|
))
|
|
|
|
url: images[itemIndex],
|
|
|
|
: Image.asset("assets/images/${isPdf ? "pdf" : isExcel ? "excel" : "doc"}.png")),
|
|
|
|
boxFit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
height: 48,
|
|
|
|
).onPress(() async {
|
|
|
|
width: 48,
|
|
|
|
if (isImage) {
|
|
|
|
))
|
|
|
|
Navigator.of(context).push(
|
|
|
|
: Image.asset("assets/images/${isPdf ? "pdf" : isExcel ? "excel" : "doc"}.png")),
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
|
|
|
builder: (_) => Scaffold(
|
|
|
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
|
|
|
child: Stack(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
// InteractiveViewer(child: Image(image: getImageObject(itemIndex))).center,
|
|
|
|
|
|
|
|
InteractiveViewer(child: getImageWidget(itemIndex)).center,
|
|
|
|
|
|
|
|
const ABackButton(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
8.width,
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
);
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
} else if (_isLocalUrl(images[itemIndex])) {
|
|
|
|
children: [
|
|
|
|
OpenFile.open(images[itemIndex]);
|
|
|
|
EllipsizedText(
|
|
|
|
} else {
|
|
|
|
images[itemIndex].split("/").last,
|
|
|
|
try {
|
|
|
|
style: AppTextStyles.heading6.copyWith(color: AppColor.black10),
|
|
|
|
if (!await launchUrl(Uri.parse(images[itemIndex]), mode: LaunchMode.externalApplication)) {
|
|
|
|
type: EllipsisType.start, // or EllipsisType.middle
|
|
|
|
Fluttertoast.showToast(msg: "UnExpected Error with file.");
|
|
|
|
),
|
|
|
|
throw Exception('Could not launch ');
|
|
|
|
4.height,
|
|
|
|
|
|
|
|
RichText(
|
|
|
|
|
|
|
|
text: TextSpan(
|
|
|
|
|
|
|
|
text: 'Asset Guide | ',
|
|
|
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.neutral120),
|
|
|
|
|
|
|
|
children: <TextSpan>[
|
|
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
|
|
text: 'View',
|
|
|
|
|
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
|
|
|
|
..onTap = () async {
|
|
|
|
|
|
|
|
if (isImage) {
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
|
|
|
builder: (_) => Scaffold(
|
|
|
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
|
|
|
child: Stack(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
// InteractiveViewer(child: Image(image: getImageObject(itemIndex))).center,
|
|
|
|
|
|
|
|
InteractiveViewer(child: getImageWidget(itemIndex)).center,
|
|
|
|
|
|
|
|
const ABackButton(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else if (_isLocalUrl(images[itemIndex])) {
|
|
|
|
|
|
|
|
OpenFile.open(images[itemIndex]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (!await launchUrl(Uri.parse(images[itemIndex]), mode: LaunchMode.externalApplication)) {
|
|
|
|
|
|
|
|
Fluttertoast.showToast(msg: "UnExpected Error with file.");
|
|
|
|
|
|
|
|
throw Exception('Could not launch ');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
|
|
|
Fluttertoast.showToast(msg: "No Viewer found.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.primary10, decoration: TextDecoration.underline),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
).expanded
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
separatorBuilder: (cxt, index) => 8.height,
|
|
|
|
|
|
|
|
itemCount: images.length)
|
|
|
|
|
|
|
|
: GridView.builder(
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
|
|
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6, mainAxisSpacing: 8, crossAxisSpacing: 8),
|
|
|
|
|
|
|
|
itemCount: images.length,
|
|
|
|
|
|
|
|
itemBuilder: (context, itemIndex) {
|
|
|
|
|
|
|
|
if (!images[itemIndex].contains(".")) {
|
|
|
|
|
|
|
|
return const Text("Bad\nFile");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
var isImage =
|
|
|
|
Fluttertoast.showToast(msg: "No Viewer found.");
|
|
|
|
images[itemIndex].split(".").last.toLowerCase() == "png" || images[itemIndex].split(".").last.toLowerCase() == "jpg" || images[itemIndex].split(".").last.toLowerCase() == "jpeg";
|
|
|
|
}
|
|
|
|
var isPdf = images[itemIndex].split(".").last.toLowerCase() == "pdf";
|
|
|
|
}
|
|
|
|
var isExcel = images[itemIndex].split(".").last.toLowerCase() == "xlsx";
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
return Container(
|
|
|
|
);
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
|
|
|
side: const BorderSide(width: 1, color: Color(0xFFEAF1F4)),
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
child: ClipRRect(
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
|
|
|
child: (isImage
|
|
|
|
|
|
|
|
? (_isLocalUrl(images[itemIndex])
|
|
|
|
|
|
|
|
? Image.file(File(images[itemIndex]))
|
|
|
|
|
|
|
|
: ImageLoader(
|
|
|
|
|
|
|
|
url: images[itemIndex],
|
|
|
|
|
|
|
|
boxFit: BoxFit.cover,
|
|
|
|
|
|
|
|
height: 48,
|
|
|
|
|
|
|
|
width: 48,
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
: Image.asset("assets/images/${isPdf ? "pdf" : isExcel ? "excel" : "doc"}.png")),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
).onPress(() async {
|
|
|
|
|
|
|
|
if (isImage) {
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
|
|
|
builder: (_) => Scaffold(
|
|
|
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
|
|
|
child: Stack(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
// InteractiveViewer(child: Image(image: getImageObject(itemIndex))).center,
|
|
|
|
|
|
|
|
InteractiveViewer(child: getImageWidget(itemIndex)).center,
|
|
|
|
|
|
|
|
const ABackButton(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else if (_isLocalUrl(images[itemIndex])) {
|
|
|
|
|
|
|
|
OpenFile.open(images[itemIndex]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (!await launchUrl(Uri.parse(images[itemIndex]), mode: LaunchMode.externalApplication)) {
|
|
|
|
|
|
|
|
Fluttertoast.showToast(msg: "UnExpected Error with file.");
|
|
|
|
|
|
|
|
throw Exception('Could not launch ');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
|
|
|
Fluttertoast.showToast(msg: "No Viewer found.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// return ListView.separated(
|
|
|
|
// return ListView.separated(
|
|
|
|
// padding: padding ?? EdgeInsets.symmetric(horizontal: 32 * AppStyle.getScaleFactor(context)),
|
|
|
|
// padding: padding ?? EdgeInsets.symmetric(horizontal: 32 * AppStyle.getScaleFactor(context)),
|
|
|
|
|