-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch image #229
Fetch image #229
Changes from all commits
828d1da
edcb52d
d798883
b73c3ab
3c86637
aab6921
0fe5a0b
a038a82
6d87963
902f0e9
c4ca98f
bf2994c
677bb8f
3334da6
f65fa38
0f6d86f
5b4b53c
e9fe430
4c8894a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,5 +43,5 @@ app.*.map.json | |
/android/app/profile | ||
/android/app/release | ||
|
||
# API secrets | ||
*.env | ||
# env variables and secrets | ||
*.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
import 'package:ipfs_client_flutter/ipfs_client_flutter.dart'; | ||
|
||
class IPFSManager { | ||
final serverUlr = 'https://ipfs.infura.io:5001'; | ||
late IpfsClient ipfsClient; | ||
|
||
IPFSManager() { | ||
final apiKeySecret = dotenv.env['IPFS_API_KEY_SECRET']; | ||
ipfsClient = IpfsClient(url: serverUlr, authorizationToken: apiKeySecret); | ||
} | ||
|
||
Future getImage(String imageToken) async { | ||
final response = await ipfsClient.read(dir: imageToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @n13 this doesnt work. it fail. can you take a look when you get some time pls. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm |
||
return response; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,136 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_svg/flutter_svg.dart'; | ||
import 'package:hypha_wallet/core/network/models/dao_data_model.dart'; | ||
import 'package:hypha_wallet/design/hypha_card.dart'; | ||
import 'package:hypha_wallet/design/hypha_colors.dart'; | ||
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
/// Render an IPFS image | ||
/// | ||
/// Images come in the form '<hash>:type' - we use type to render correctly | ||
/// | ||
/// Supports svg and bitmap images | ||
/// | ||
class IpfsImage extends StatelessWidget { | ||
final String ipfsHash; | ||
final String type; | ||
|
||
late final String url = 'https://ipfs.io/ipfs/$ipfsHash'; | ||
|
||
IpfsImage({super.key, required this.ipfsHash, required this.type}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
switch (type) { | ||
case 'svg': | ||
return SvgPicture.network(url); | ||
case 'png': | ||
case 'jpg': | ||
case 'jpeg': | ||
case 'gif': | ||
case 'bmp': | ||
case 'webp': | ||
return Image.network(url); | ||
default: | ||
return const Icon(Icons.error, color: Colors.red); // Default error icon in case the format isn't supported. | ||
} | ||
} | ||
} | ||
|
||
class DaoWidget extends StatelessWidget { | ||
final DaoData dao; | ||
|
||
String get daoUrl => 'https://dao.hypha.earth/${dao.settingsDaoUrl}'; | ||
|
||
const DaoWidget({ | ||
super.key, | ||
required this.dao, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 22), | ||
child: HyphaCard( | ||
child: InkWell( | ||
borderRadius: BorderRadius.circular(16), | ||
onTap: () {}, | ||
child: Padding( | ||
padding: const EdgeInsets.only(left: 22, right: 22, top: 12, bottom: 22), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
ListTile( | ||
dense: true, | ||
// leading: FutureBuilder<String>( | ||
// future: fetchSVGFromIPFS('QmV3KmaoqCCXuCDvHzYWS9Jg3RfjrDTQSXK1e7453qfSRS'), | ||
// builder: (context, snapshot) { | ||
// if (snapshot.connectionState == ConnectionState.waiting) { | ||
// return CircularProgressIndicator(); | ||
// } else if (snapshot.hasError) { | ||
// return Text('Error: ${snapshot.error}'); | ||
// } else { | ||
// return SvgPicture.string(snapshot.data!); | ||
// } | ||
// }, | ||
// ), | ||
visualDensity: VisualDensity.compact, | ||
title: Text(dao.settingsDaoTitle, style: context.hyphaTextTheme.smallTitles), | ||
), | ||
// const SizedBox(height: 14), | ||
// const HyphaDivider(), | ||
// const SizedBox(height: 20), | ||
], | ||
return HyphaCard( | ||
child: InkWell( | ||
borderRadius: BorderRadius.circular(16), | ||
onTap: () async { | ||
if (!await launchUrl(Uri.parse(daoUrl), mode: LaunchMode.externalApplication)) { | ||
throw Exception('Could not launch $daoUrl'); | ||
} | ||
}, | ||
child: Stack( | ||
children: [ | ||
const Positioned( | ||
right: 12, | ||
top: 12, | ||
child: Icon(Icons.navigate_next), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(24), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
children: [ | ||
Container( | ||
width: 48, | ||
height: 48, | ||
decoration: const BoxDecoration( | ||
shape: BoxShape.circle, | ||
color: | ||
Colors.white, // Note: white bg is standard on the DAO website where people upload images | ||
), | ||
child: ClipOval( | ||
child: IpfsImage( | ||
ipfsHash: dao.logoIPFSHash, | ||
type: dao.logoType, | ||
), | ||
), | ||
), | ||
const SizedBox(width: 8), | ||
Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text(dao.settingsDaoTitle, style: context.hyphaTextTheme.smallTitles), | ||
Text( | ||
'dao.hypha.earth/${dao.settingsDaoUrl}', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this field was called short URL or something |
||
style: context.hyphaTextTheme.reducedTitles.copyWith(color: HyphaColors.primaryBlu), | ||
), | ||
], | ||
) | ||
], | ||
), | ||
// const SizedBox(height: 12), | ||
// const HyphaDivider(), | ||
// const SizedBox(height: 12), | ||
// Row( | ||
// crossAxisAlignment: CrossAxisAlignment.center, | ||
// mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
// children: [ | ||
// Row( | ||
// children: [ | ||
// const Icon(Icons.calendar_month), | ||
// const SizedBox(width: 4), | ||
// Text( | ||
// 'The date here', | ||
// style: context.hyphaTextTheme.ralMediumSmallNote.copyWith( | ||
// height: 0, | ||
// color: HyphaColors.midGrey, | ||
// ), | ||
// ), | ||
// ], | ||
// ), | ||
// Text('Core member', style: context.hyphaTextTheme.ralMediumBody.copyWith(height: 0)), | ||
// ], | ||
// ) | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
// Future<String> fetchSVGFromIPFS(String ipfsHash) async { | ||
// final ipfsURL = 'https://ipfs.io/ipfs/$ipfsHash:svg'; | ||
// final response = await http.get(Uri.parse(ipfsURL)); | ||
// | ||
// if (response.statusCode == 200) { | ||
// return response.body; | ||
// } else { | ||
// throw Exception('Failed to fetch SVG from IPFS. Status code: ${response.statusCode}'); | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok... guess we need secret - let's load it from firebase?! At least it won't be in the code then..