diff --git a/lib/bottom_navigation_bar_buttons/home_page/home_page.dart b/lib/bottom_navigation_bar_buttons/home_page/home_page.dart new file mode 100644 index 0000000000000000000000000000000000000000..f992c36ef2bbf611a4531d5d3deced39c633a82d --- /dev/null +++ b/lib/bottom_navigation_bar_buttons/home_page/home_page.dart @@ -0,0 +1,97 @@ +import 'package:deggendorf_app/bottom_navigation_bar_buttons/home_page/list_of_widgets_for_home_page.dart'; +import 'package:deggendorf_app/bottom_navigation_bar_buttons/home_page/weather/current_weather.dart'; +import 'package:deggendorf_app/main.dart'; +import 'package:flutter/material.dart'; + +class HomePage extends StatelessWidget { + const HomePage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + home: MyStatefulWidget(), + ); + } +} + +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); +} + +class _MyStatefulWidgetState extends State<MyStatefulWidget> { + List<int> bottom = <int>[0]; + + @override + Widget build(BuildContext context) { + const Key centerKey = ValueKey<String>('bottom-sliver-list'); + return Scaffold( + appBar: AppBar( + title: const Text('Deggendorf App'), + ), + drawer: Drawer( + child: ListView( + padding: EdgeInsets.zero, + children: [ + const DrawerHeader( + decoration: BoxDecoration( + color: Colors.blue, + ), + child: Text('Drawer Header'), + ), + ListTile( + title: const Text('Option 1'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const SecondRoute())); + }, + ), + ListTile( + title: const Text('Option 2'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const SecondRoute())); + }, + ), + ], + ), + ), + body: CustomScrollView( + center: centerKey, + slivers: <Widget>[ + SliverList( + key: centerKey, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return new InkWell( + onTap: () { + if (index == 0) { + //If the widget tapped is the weather widget, then open weather page :) + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const CurrentWeather()), + ); + } + }, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20)), + height: 125, + child: new MyList(context).myList[index], + )); + }, + childCount: new MyList(context).myList.length, + ), + ), + ], + ), + ); + } +} diff --git a/lib/bottom_navigation_bar_buttons/home_page/list_of_widgets_for_home_page.dart b/lib/bottom_navigation_bar_buttons/home_page/list_of_widgets_for_home_page.dart new file mode 100644 index 0000000000000000000000000000000000000000..05a8fa1293fbef1b809844fc7568b3cf04c4f70d --- /dev/null +++ b/lib/bottom_navigation_bar_buttons/home_page/list_of_widgets_for_home_page.dart @@ -0,0 +1,20 @@ +import 'package:deggendorf_app/bottom_navigation_bar_buttons/home_page/weather/current_weather.dart'; +import 'package:flutter/cupertino.dart'; + +class MyList { + List<Widget> myList = []; + MyList(BuildContext buildContext) { + myList = [ + actualWeatherContainer(buildContext), + Text("Input your widget here"), + Text("Input your widget here"), + Text("Input your widget here"), + Text("Input your widget here"), + Text("Input your widget here"), + Text("Input your widget here"), + Text("Input your widget here"), + Text("Input your widget here"), + ]; + } + +} diff --git a/lib/bottom_navigation_bar_buttons/home_page/weather/current_weather.dart b/lib/bottom_navigation_bar_buttons/home_page/weather/current_weather.dart new file mode 100644 index 0000000000000000000000000000000000000000..efba287171f4e4423469e6a9b9a809f7ced3fc4c --- /dev/null +++ b/lib/bottom_navigation_bar_buttons/home_page/weather/current_weather.dart @@ -0,0 +1,108 @@ +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'package:google_fonts/google_fonts.dart'; + +import 'weather.dart'; + +class CurrentWeather extends StatefulWidget { + const CurrentWeather({Key? key}) : super(key: key); + + @override + _CurrentWeatherState createState() => _CurrentWeatherState(); +} + +class _CurrentWeatherState extends State<CurrentWeather> { + late WeatherData weather; + + @override + Widget build(BuildContext buildContext) { + return Container( + child: Scaffold( + appBar: AppBar( + title: const Text("Deggendorf"), + ), + body: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Flexible( + flex: 1, + fit: FlexFit.loose, + child: actualWeatherContainer(context)) + ]))); + } +} + +Container actualWeatherContainer(BuildContext context) { + late WeatherData weather; + return Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height, + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/chuttersnap-TSgwbumanuE-unsplash1.jpg'), + fit: BoxFit.cover)), + child: FutureBuilder( + builder: (buildContext, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + weather = snapshot.data as WeatherData; + if (weather == null) { + return const Text("Error getting weather"); + } else { + return weatherBox(weather); + } + } else { + return const CircularProgressIndicator(); + } + }, + future: getCurrentWeather(), + ), + ); +} + +Widget weatherBox(WeatherData weather) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + //padding: const EdgeInsets.fromLTRB(0, 150, 0, 0), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text("${weather.temperature}°C", + style: GoogleFonts.dancingScript( + fontSize: 65, + color: Color.fromRGBO(0, 0, 139, 0.7), + fontWeight: FontWeight.bold)), + Text("${weather.description}", + style: GoogleFonts.pacifico( + fontSize: 30, color: Color.fromRGBO(0, 0, 139, 0.7))) + ], + ), + Padding( + padding: const EdgeInsets.fromLTRB(0, 10, 0, 0), + child: Text("Feels:${weather.feelsLike}°C", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15))), + Text("Highest: ${weather.high}°C Lowest: ${weather.low}°C", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15)), + ]); +} + +Future getCurrentWeather() async { + WeatherData? weather; + String latitude = "48.8296064"; //coordinates of THD + String longitude = "12.9542545"; + String apiKey = "bdfd87b51211cb50b78a20c889a500b3"; + var url = + "https://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longitude&appid=$apiKey&units=metric"; + + final response = await http.get(Uri.parse(url)); + + if (response.statusCode == 200) { + weather = WeatherData.fromJson(jsonDecode(response.body)); + return weather; + } else { + weather = null; + FlutterError.presentError; + } +} diff --git a/lib/bottom_navigation_bar_buttons/weather/weather.dart b/lib/bottom_navigation_bar_buttons/home_page/weather/weather.dart similarity index 100% rename from lib/bottom_navigation_bar_buttons/weather/weather.dart rename to lib/bottom_navigation_bar_buttons/home_page/weather/weather.dart diff --git a/lib/bottom_navigation_bar_buttons/weather/current_weather.dart b/lib/bottom_navigation_bar_buttons/weather/current_weather.dart deleted file mode 100644 index 3ed06858c22128f0655754efb5917c2fa2a5147e..0000000000000000000000000000000000000000 --- a/lib/bottom_navigation_bar_buttons/weather/current_weather.dart +++ /dev/null @@ -1,93 +0,0 @@ -import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:http/http.dart' as http; -import 'package:google_fonts/google_fonts.dart'; - -import 'weather.dart'; - -class CurrentWeather extends StatefulWidget { - const CurrentWeather({Key? key}) : super(key: key); - - @override - _CurrentWeatherState createState() => _CurrentWeatherState(); -} - -class _CurrentWeatherState extends State<CurrentWeather> { - late WeatherData weather; - - @override - Widget build(BuildContext buildContext) { - return Container( - child: Scaffold( - appBar: AppBar( - title: const Text("Deggendorf"), - ), - body: - Column(mainAxisAlignment: MainAxisAlignment.center, children: [ - Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height - 56, - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage( - 'assets/chuttersnap-TSgwbumanuE-unsplash1.jpg'), - fit: BoxFit.cover)), - child: FutureBuilder( - builder: (buildContext, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - weather = snapshot.data as WeatherData; - if (weather == null) { - return const Text("Error getting weather"); - } else { - return weatherBox(weather); - } - } else { - return const CircularProgressIndicator(); - } - }, - future: getCurrentWeather(), - ), - ) - ]))); - } -} - -Widget weatherBox(WeatherData weather) { - return Column(children: <Widget>[ - Padding( - padding: const EdgeInsets.fromLTRB(0, 150, 0, 0), - child: Text("${weather.temperature}°C", - style: GoogleFonts.dancingScript( - fontSize: 65, - color: Color.fromRGBO(0, 0, 139, 0.7), - fontWeight: FontWeight.bold))), - Text("${weather.description}", - style: GoogleFonts.pacifico( - fontSize: 30, color: Color.fromRGBO(0, 0, 139, 0.7))), - Padding( - padding: const EdgeInsets.fromLTRB(0, 50, 0, 0), - child: Text("Feels:${weather.feelsLike}°C", - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15))), - Text("Highest: ${weather.high}°C Lowest: ${weather.low}°C", - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15)), - ]); -} - -Future getCurrentWeather() async { - WeatherData? weather; - String latitude = "48.8296064"; //coordinates of THD - String longitude = "12.9542545"; - String apiKey = "bdfd87b51211cb50b78a20c889a500b3"; - var url = - "https://api.openweathermap.org/data/2.5/weather?lat=$latitude&lon=$longitude&appid=$apiKey&units=metric"; - - final response = await http.get(Uri.parse(url)); - - if (response.statusCode == 200) { - weather = WeatherData.fromJson(jsonDecode(response.body)); - return weather; - } else { - weather = null; - FlutterError.presentError; - } -} diff --git a/lib/main.dart b/lib/main.dart index 5a6d0467042eabd2866494eabb3ef8b363a98478..07b800e1677a70bdbd10566d0eb88207ff5e490b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,8 @@ -import 'package:deggendorf_app/bottom_navigation_bar_buttons/weather/current_weather.dart'; +import 'package:deggendorf_app/bottom_navigation_bar_buttons/home_page/home_page.dart'; import 'package:flutter/material.dart'; import 'bottom_navigation_bar_buttons/forum/forum.dart'; +import 'bottom_navigation_bar_buttons/home_page/weather/current_weather.dart'; void main() { runApp(const MyApp()); @@ -43,7 +44,7 @@ class _MyHomePageState extends State<MyHomePage> { */ static const List<Widget> _widgetOptions = <Widget>[ //Index: 0 - CurrentWeather(), + HomePage(), //Index: 1, SecondRoute(), //Index: 2,