Created with <3 with dartpad.dev.
Last active
October 27, 2022 09:38
-
-
Save hongsw/675e39a751e104dd67da12239d22fd02 to your computer and use it in GitHub Desktop.
Flutter K-Web Toon Mini with Gist JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:core'; | |
import 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
void main(){ | |
runApp(MainFullDemo()); | |
} | |
class MainFullDemo extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.lightGreen, | |
), | |
home: const MyHomePage(title: '내폰내툰'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
Key? key, | |
required this.title, | |
}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
late List toon = []; | |
getTestData() async { | |
var jsonDomain = "gist.githubusercontent.com"; | |
var jsonUrl = "hongsw/67e0d72dffa2908e1715dc89a7b0e802/raw/9c5b1388bd52396ff1917b6928f3bda5fcd3b5c7/webtoon.json"; | |
var response = await http.get(Uri.https(jsonDomain,jsonUrl)); | |
var items = json.decode(utf8.decode(response.bodyBytes)); | |
setState( () { | |
toon = items['webtoon']; | |
}); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
getTestData(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
toolbarHeight: 80, | |
title: Text(widget.title, | |
style: const TextStyle( | |
fontWeight: FontWeight.w600, | |
fontSize: 36.0, | |
color: Colors.black)), | |
centerTitle: true), | |
body: Center( | |
child: | |
toon.isEmpty ? const Text('loading') : | |
Column(children: <Widget>[ | |
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0), | |
child: GestureDetector( | |
onTap: () { | |
}, | |
child: Column(children: <Widget>[ | |
Image.network(toon[0]['image']), | |
Text(toon[0]['title']), | |
]))), | |
Padding( | |
padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0), | |
child:GestureDetector( | |
onTap: () { | |
}, | |
child: Column(children: <Widget>[ | |
Image.network(toon[1]['image']), | |
Text(toon[1]['title']), | |
]))), | |
]), | |
]), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment