When I do an apk build on Flutter and on the page when retrieving JSON files to Google Drive there is an error:
Error: ClientException with SocketException: Failed host
Hookup: 'drive.google.com' (OS Error: No address
associated with hostname, errno=7), uri=https://
drive.google.com/uc?
id=1oec31VzuOSQAIXsY5Lu0eJAFIeWJrM4s
Which when I do debugging there is no error like that.
My Code:
import 'dart:convert';
import 'package:art_ar_1/conf.dart';
import 'package:art_ar_1/processing/paint_ar_preview.dart';
import 'package:art_ar_1/views/components/CListTile.dart';
import 'package:art_ar_1/views/components/app_bar.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class ArPaintView extends StatefulWidget {
const ArPaintView({super.key});
static const String routeName = "/paint";
@override
State<ArPaintView> createState() => _ArPaintView();
}
class _ArPaintView extends State<ArPaintView> {
final String downloadUrl = Conf.PAINT_JSON;
Future<List<Map<String, String>>> _loadData() async {
final http.Response response = await http.get(Uri.parse(downloadUrl));
if (response.statusCode == 200) {
final List<dynamic> data = json.decode(response.body);
return data.map((item) => Map<String, String>.from(item)).toList();
} else {
throw Exception('Gagal me-load data :(');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const AppBarComponent(title: "AR Lukisan"),
body: FutureBuilder<List<Map<String, String>>>(
future: _loadData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return const Center(child: Text('Data kosong...'));
}
final List<Map<String, String>> data = snapshot.data!;
return ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
final item = data[index];
return CListTile(
title: item["title"] ?? '',
imageUrl: item["img_path"] ?? '',
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PaintArPreview(
fileUrl: item['model_path'] ?? "",
fileName: item['model_file_name'] ?? "",
),
));
},
);
},
);
},
),
);
}
}
PAINT_JSON URL:
“https://drive.google.com/uc?id=1oec31VzuOSQAlXsY5Lu0eJAFIeWJrM4s”
Difference debug and release
Maybe I entered the Google Drive URL format incorrectly, or there are certain settings when trying to release the APK? I don’t know, please correct me
account Incognito is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.