From 828d532206aa696b5c7391e63807f0b974a36408 Mon Sep 17 00:00:00 2001 From: anohene1 Date: Tue, 12 Oct 2021 15:50:41 +0000 Subject: [PATCH] refactored home page into new file and moved avenger_detail into new folder for best coding practices --- .idea/.gitignore | 3 + .idea/hacktoberfest21-flutter-gdsc-iiitv.iml | 14 ++ .idea/libraries/Dart_SDK.xml | 28 ++++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + data.json | 11 +- hacktoberfest21_gdsc/lib/main.dart | 129 +----------------- .../lib/{ => screens}/avenger_detail.dart | 2 +- .../lib/screens/home_page.dart | 129 ++++++++++++++++++ 9 files changed, 201 insertions(+), 129 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/hacktoberfest21-flutter-gdsc-iiitv.iml create mode 100644 .idea/libraries/Dart_SDK.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml rename hacktoberfest21_gdsc/lib/{ => screens}/avenger_detail.dart (99%) create mode 100644 hacktoberfest21_gdsc/lib/screens/home_page.dart diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/hacktoberfest21-flutter-gdsc-iiitv.iml b/.idea/hacktoberfest21-flutter-gdsc-iiitv.iml new file mode 100644 index 0000000..8a91231 --- /dev/null +++ b/.idea/hacktoberfest21-flutter-gdsc-iiitv.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml new file mode 100644 index 0000000..62be7ea --- /dev/null +++ b/.idea/libraries/Dart_SDK.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9f24019 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/data.json b/data.json index 262654b..6c03848 100644 --- a/data.json +++ b/data.json @@ -340,6 +340,15 @@ "linkedinURL":"linkedin.com/in/angad-manroy-25b260200", "githubURL": "https://github.com/AngadManroy", "twitterURL": "" -} +}, + { + "id": 33, + "name": "Isaac Anohene", + "batch": "2021", + "imgURL": "", + "linkedinURL":"https://www.linkedin.com/in/anohene1", + "githubURL": "https://github.com/anohene1", + "twitterURL": "https://twitter.com/anohene1" + } ] } diff --git a/hacktoberfest21_gdsc/lib/main.dart b/hacktoberfest21_gdsc/lib/main.dart index 672ae15..5087d2f 100644 --- a/hacktoberfest21_gdsc/lib/main.dart +++ b/hacktoberfest21_gdsc/lib/main.dart @@ -1,10 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:hacktoberfest21_gdsc/avenger_detail.dart'; -import 'package:hacktoberfest21_gdsc/models/avengers.dart'; -import "package:http/http.dart" as http; -import 'dart:convert'; +import 'screens/home_page.dart'; + -import 'package:url_launcher/url_launcher.dart'; void main() => runApp(MaterialApp( title: "Avengers", @@ -12,125 +9,3 @@ void main() => runApp(MaterialApp( theme: ThemeData(primarySwatch: Colors.teal), home: HomePage(), )); - -class HomePage extends StatefulWidget { - @override - _HomePageState createState() => _HomePageState(); -} - -class _HomePageState extends State { - var url = Uri.parse( - "https://raw.githubusercontent.com/iiitv/hacktoberfest21-flutter-gdsc-iiitv/main/data.json"); - - DataHub? dataHub; - @override - void initState() { - super.initState(); - - fetchData(); - } - - fetchData() async { - var res = await http.get(url); - var decodedValue = jsonDecode(res.body); - dataHub = DataHub.fromJson(decodedValue); - setState(() {}); - } - - @override - Widget build(BuildContext context) { - var size = MediaQuery.of(context).size; - - final double itemHeight = (size.height - kToolbarHeight - 240) / 2; - final double itemWidth = size.width / 2; - - return Scaffold( - appBar: AppBar( - centerTitle: true, - title: const Text("GDSC-Hacktoberfest21"), - ), - body: dataHub == null - ? const Center( - child: CircularProgressIndicator(), - ) - : RefreshIndicator( - onRefresh: () { - return Future.delayed( - const Duration(seconds: 1), - () { - setState(() { - fetchData(); - }); - }, - ); - }, - child: GridView.count( - crossAxisCount: 2, - childAspectRatio: (itemWidth / itemHeight), - children: dataHub!.data - .map((Data avenge) => Padding( - padding: const EdgeInsets.all(2.0), - child: InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => AvengerDetail( - data: avenge, - ))); - }, - child: Card( - elevation: 3.0, - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - children: [ - Hero( - tag: avenge.imgURL.toString(), - child: Container( - height: - MediaQuery.of(context).size.height / - 4, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - avenge.imgURL.toString())), - ), - ), - ), - Text(avenge.name.toString(), - style: const TextStyle( - fontSize: 18.0, - fontWeight: FontWeight.bold)), - ], - ), - ), - ), - )) - .toList()), - ), - bottomNavigationBar: BottomAppBar( - child: SizedBox( - child: InkWell( - child: Container( - color: Colors.teal, - height: MediaQuery.of(context).size.height / 20, - // ng: EdgeInsets.all(8.0),paddi - child: const Center( - child: Text( - " by GDSC IIITV", - style: TextStyle( - fontSize: 20, - ), - textAlign: TextAlign.center, - ), - ), - ), - onTap: () => launch( - 'https://iiitv.github.io/hacktoberfest21-flutter-gdsc-iiitv/'), - ), - ), - ), - ); - } -} diff --git a/hacktoberfest21_gdsc/lib/avenger_detail.dart b/hacktoberfest21_gdsc/lib/screens/avenger_detail.dart similarity index 99% rename from hacktoberfest21_gdsc/lib/avenger_detail.dart rename to hacktoberfest21_gdsc/lib/screens/avenger_detail.dart index 7ba71e3..9b10963 100644 --- a/hacktoberfest21_gdsc/lib/avenger_detail.dart +++ b/hacktoberfest21_gdsc/lib/screens/avenger_detail.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; -import 'models/avengers.dart'; +import '../models/avengers.dart'; class AvengerDetail extends StatelessWidget { final Data data; diff --git a/hacktoberfest21_gdsc/lib/screens/home_page.dart b/hacktoberfest21_gdsc/lib/screens/home_page.dart new file mode 100644 index 0000000..58d5f91 --- /dev/null +++ b/hacktoberfest21_gdsc/lib/screens/home_page.dart @@ -0,0 +1,129 @@ +import 'package:flutter/material.dart'; +import 'package:hacktoberfest21_gdsc/models/avengers.dart'; +import 'package:url_launcher/url_launcher.dart'; +import "package:http/http.dart" as http; +import 'dart:convert'; +import 'avenger_detail.dart'; + + +class HomePage extends StatefulWidget { + @override + _HomePageState createState() => _HomePageState(); +} + +class _HomePageState extends State { + var url = Uri.parse( + "https://raw.githubusercontent.com/iiitv/hacktoberfest21-flutter-gdsc-iiitv/main/data.json"); + + DataHub? dataHub; + @override + void initState() { + super.initState(); + + fetchData(); + } + + fetchData() async { + var res = await http.get(url); + var decodedValue = jsonDecode(res.body); + dataHub = DataHub.fromJson(decodedValue); + setState(() {}); + } + + @override + Widget build(BuildContext context) { + var size = MediaQuery.of(context).size; + + final double itemHeight = (size.height - kToolbarHeight - 240) / 2; + final double itemWidth = size.width / 2; + + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: const Text("GDSC-Hacktoberfest21"), + ), + body: dataHub == null + ? const Center( + child: CircularProgressIndicator(), + ) + : RefreshIndicator( + onRefresh: () { + return Future.delayed( + const Duration(seconds: 1), + () { + setState(() { + fetchData(); + }); + }, + ); + }, + child: GridView.count( + crossAxisCount: 2, + childAspectRatio: (itemWidth / itemHeight), + children: dataHub!.data + .map((Data avenge) => Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => AvengerDetail( + data: avenge, + ))); + }, + child: Card( + elevation: 3.0, + child: Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + children: [ + Hero( + tag: avenge.imgURL.toString(), + child: Container( + height: + MediaQuery.of(context).size.height / + 4, + decoration: BoxDecoration( + image: DecorationImage( + image: NetworkImage( + avenge.imgURL.toString())), + ), + ), + ), + Text(avenge.name.toString(), + style: const TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.bold)), + ], + ), + ), + ), + )) + .toList()), + ), + bottomNavigationBar: BottomAppBar( + child: SizedBox( + child: InkWell( + child: Container( + color: Colors.teal, + height: MediaQuery.of(context).size.height / 20, + // ng: EdgeInsets.all(8.0),paddi + child: const Center( + child: Text( + " by GDSC IIITV", + style: TextStyle( + fontSize: 20, + ), + textAlign: TextAlign.center, + ), + ), + ), + onTap: () => launch( + 'https://iiitv.github.io/hacktoberfest21-flutter-gdsc-iiitv/'), + ), + ), + ), + ); + } +}