Itempage
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Flummi 2022-05-30 02:29:52 +02:00
parent 89658791bb
commit ca98d86e26
6 changed files with 152 additions and 18 deletions

25
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,25 @@
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "f0ckapp",
"request": "launch",
"type": "dart"
},
{
"name": "f0ckapp (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "f0ckapp (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}

15
lib/api/fetchitem.dart Normal file
View File

@ -0,0 +1,15 @@
import 'package:f0ckapp/model/item.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<Item> fetchItemFromApi(id) async {
final response = await http.get(Uri.parse('https://f0ck.dev/api/v2/item/$id'));
if(response.statusCode == 200) {
//List jsonresponse = json.decode(response.body)['rows'];
Map<String, dynamic> jsonresponse = json.decode(response.body)['rows'];
return Item.fromJson(jsonresponse);
} else {
throw Exception('failed to load feed');
}
}

View File

@ -1,11 +1,28 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:f0ckapp/view/home.dart'; import 'package:f0ckapp/view/home.dart';
import 'package:f0ckapp/view/item.dart';
void main() { /*void main() {
runApp(MaterialApp( runApp(MaterialApp(
theme: ThemeData( theme: ThemeData(
scaffoldBackgroundColor: const Color.fromARGB(255, 23, 23, 23) scaffoldBackgroundColor: const Color.fromARGB(255, 23, 23, 23)
), ),
home: const Home() home: const Home()
)); ));
}*/
void main() async {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
theme: ThemeData(
scaffoldBackgroundColor: const Color.fromARGB(255, 23, 23, 23)
),
routes: {
'/': (context) => const Home(),
'/detail': (context) => const ItemPage(id: 0),
}
),
);
} }

View File

@ -2,18 +2,21 @@ class Item {
int id; int id;
String mime; String mime;
int tagId; int tagId;
String dest;
Item({ Item({
required this.id, required this.id,
required this.mime, required this.mime,
required this.tagId this.tagId = 0,
this.dest = ''
}); });
factory Item.fromJson(Map<String, dynamic> data) { factory Item.fromJson(Map<String, dynamic> data) {
return Item( return Item(
id: data['id'], id: data['id'],
mime: data['mime'], mime: data['mime'],
tagId: data['tag_id'] tagId: data['tag_id'] ?? 0,
dest: data['dest'] ?? ''
); );
} }
} }

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:f0ckapp/api/fetchdata.dart'; import 'package:f0ckapp/api/fetchdata.dart';
import 'package:f0ckapp/model/item.dart'; import 'package:f0ckapp/model/item.dart';
import 'package:f0ckapp/view/item.dart';
class Home extends StatefulWidget { class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key); const Home({Key? key}) : super(key: key);
@ -49,7 +50,16 @@ class _HomeState extends State<Home> {
case 2: mode = Colors.red; break; case 2: mode = Colors.red; break;
default: mode = Colors.yellow; break; default: mode = Colors.yellow; break;
} }
return Stack( return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ItemPage(id: snapshot.data![index].id),
),
);
},
child: Stack(
children: <Widget>[ children: <Widget>[
Image.network("https://f0ck.dev/t/${snapshot.data?[index].id}.webp"), Image.network("https://f0ck.dev/t/${snapshot.data?[index].id}.webp"),
SizedBox( SizedBox(
@ -66,6 +76,7 @@ class _HomeState extends State<Home> {
), ),
) )
] ]
)
); );
}, },
childCount: snapshot.data?.length childCount: snapshot.data?.length

63
lib/view/item.dart Normal file
View File

@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:f0ckapp/model/item.dart';
import 'package:f0ckapp/api/fetchitem.dart';
class ItemPage extends StatefulWidget {
final int id;
const ItemPage({Key? key, required this.id }) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_ItemPageState createState() => _ItemPageState();
}
class _ItemPageState extends State<ItemPage> with SingleTickerProviderStateMixin {
late final int id;
late Future<Item> f0ck;
@override
void initState() {
super.initState();
id = widget.id;
f0ck = fetchItemFromApi(id);
}
@override
Widget build(BuildContext context) {
return FutureBuilder<Item>(
future: f0ck,
builder: (context, snapshot) {
if(snapshot.hasData) {
return Scaffold(
appBar: AppBar(
title: Text('f0ck $id'),
),
body: Column(
children: [
AspectRatio(
aspectRatio: 1,
child: SizedBox(
width: double.infinity,
child: snapshot.data!.mime.startsWith('image') ? Image.network("https://f0ck.dev/b/${snapshot.data?.dest}") : const Text("no image"),
),
),
Container(
margin: const EdgeInsets.all(20.0),
child: Center(
child: Text(
"${snapshot.data?.mime}",
style: const TextStyle(fontSize: 40),
),
),
),
],
),
);
} else if(snapshot.hasError) {
return Text("${snapshot.error}");
}
return const CircularProgressIndicator();
}
);
}
}