f0ckapp/lib/view/item.dart
Flummi ca98d86e26
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Itempage
2022-05-30 02:29:52 +02:00

64 lines
1.8 KiB
Dart

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();
}
);
}
}