fml
This commit is contained in:
81
lib/view/home.dart
Normal file
81
lib/view/home.dart
Normal file
@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:f0ckapp/model/item.dart';
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
// ignore: library_private_types_in_public_api
|
||||
_HomeState createState() => _HomeState();
|
||||
}
|
||||
|
||||
class _HomeState extends State<Home> {
|
||||
List data = [];
|
||||
List<Item> f0cks = <Item>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
fetchDataFromApi();
|
||||
}
|
||||
|
||||
Future<bool> fetchDataFromApi() async {
|
||||
final jsondata = await http.get(Uri.parse('https://f0ck.dev/api/v2/items/get?mode=3'));
|
||||
final list = json.decode(jsondata.body)['items'] as List<dynamic>;
|
||||
setState(() {
|
||||
f0cks = list.map((e) => Item.fromJson(e)).toList();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
backgroundColor: const Color.fromARGB(255, 43, 43, 43),
|
||||
title: const Text('f0cks'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: GridView.builder(
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3
|
||||
),
|
||||
itemCount: f0cks.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
|
||||
Color mode;
|
||||
switch(f0cks[index].tagId) {
|
||||
case 1: mode = Colors.green; break;
|
||||
case 2: mode = Colors.red; break;
|
||||
default: mode = Colors.yellow; break;
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
Image.network("https://f0ck.dev/t/${f0cks[index].id}.webp"),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: FractionalOffset.bottomRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 5.0, right: 5.0),
|
||||
child: Icon(
|
||||
Icons.square,
|
||||
color: mode,
|
||||
size: 20.0
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
]
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user