Skip to content
Snippets Groups Projects
Commit 3fb53f9c authored by Chaitanya's avatar Chaitanya
Browse files

First version of bottom navigation bar

parent bbd8ad86
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/material.dart';
import '../../main.dart';
class Forum extends StatefulWidget {
const Forum({Key? key}) : super(key: key);
@override
State<Forum> createState() => _ForumState();
}
class _ForumState extends State<Forum> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Forum"),
),
body: Column(
children: <Widget>[
ForumFolder(
iconData: Icons.account_balance_outlined,
title: "Aufenthalt",
),
ForumFolder(
iconData: Icons.account_box_outlined,
title: "Jobbörse",
),
ForumFolder(
iconData: Icons.alternate_email,
title: "Allgemein",
)
],
),
);
}
}
class ForumFolder extends StatefulWidget {
ForumFolder({
Key? key,
required this.iconData,
required this.title,
}) : super(key: key);
IconData iconData;
String title;
@override
State<ForumFolder> createState() => _ForumFolderState();
}
class _ForumFolderState extends State<ForumFolder> {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Padding(
padding: EdgeInsetsDirectional.fromSTEB(20, 5, 10, 5),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SecondRoute()),
);
},
child: Row(
children: [
Icon(
widget.iconData,
color: Colors.black,
),
Text(
" " + widget.title,
style: TextStyle(fontSize: 30, color: Colors.black),
)
],
),
)),
],
);
}
}
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;
}
}
class WeatherData {
final double temperature;
final double feelsLike;
final double low;
final double high;
final String description;
WeatherData({required this.temperature, required this.feelsLike, required this.low, required this.high, required this.description});
factory WeatherData.fromJson(Map<String, dynamic> json) {
return WeatherData(
temperature: json['main']['temp'].toDouble(),
feelsLike: json['main']['feels_like'].toDouble(),
low: json['main']['temp_min'].toDouble(),
high: json['main']['temp_max'].toDouble(),
description: json['weather'][0]['description'],
);
}
}
\ No newline at end of file
import 'package:deggendorf_app/bottom_navigation_bar_buttons/weather/current_weather.dart';
import 'package:flutter/material.dart';
import 'bottom_navigation_bar_buttons/forum/forum.dart';
void main() {
runApp(const MyApp());
}
......@@ -11,17 +14,8 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
title: 'Deggendorf App',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'DeggApp'),
......@@ -32,15 +26,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
......@@ -48,77 +33,98 @@ class MyHomePage extends StatefulWidget {
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
int _selectedIndex = 0;
/*
Here is the list where the widgets for the bottom navigation bar are
The list starts at index zero
An exception has yet to be implemented which will be triggered whenever there
is not enough widget for the number of buttons
*/
static const List<Widget> _widgetOptions = <Widget>[
//Index: 0
CurrentWeather(),
//Index: 1,
SecondRoute(),
//Index: 2,
Forum(),
//Index: 3
SecondRoute(),
//Index: 4
SecondRoute()
];
void _onItemTapped(int index) {
setState(() {
_counter++;
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
/*
Here is where the magic takes place :)
Each of the navigation bar item has an index starting from 0
This index is used to refer to a list and call widgets
*/
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
body: Column(
children: [
MenuButton(title: "Wetter", iconData: Icons.ac_unit),
MenuButton(title: "Karte", iconData: Icons.location_on),
MenuButton(title: "Nachrichten", iconData: Icons.new_releases_sharp),
MenuButton(title: "Events", iconData: Icons.alternate_email)
/*
From here are the bottom navigation bar's buttons
Each button has an icon, a label and a colour, each of which are optional
*/
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
backgroundColor: Colors.blue,
),
BottomNavigationBarItem(
icon: Icon(Icons.alternate_email),
label: 'Event',
backgroundColor: Colors.green,
),
BottomNavigationBarItem(
icon: Icon(Icons.accessibility_sharp),
label: 'Forum',
backgroundColor: Colors.purple,
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: 'Konto',
backgroundColor: Colors.brown,
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Einstellung',
backgroundColor: Colors.pink,
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class MenuButton extends StatefulWidget {
const MenuButton({Key? key,
required this.title,
required this.iconData,
}) : super(key: key);
final String title;
final IconData iconData;
@override
State<MenuButton> createState() => _MenuButtonState();
}
class _MenuButtonState extends State<MenuButton> {
void _incrementCounter() async{
setState(() {
});
}
/*
This is a default route shown wherever a page is not developed yet
*/
class SecondRoute extends StatelessWidget {
const SecondRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return InkWell(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(20, 20, 20, 20),
child: Row(
children: <Widget>[
Icon(widget.iconData, color: Colors.blue, size: 30,),
Text(" " + widget.title, style: TextStyle(fontSize: 25, color: Colors.black),)
],
),
)
],
)
return Scaffold(
appBar: AppBar(
title: const Text('Second Route'),
),
body: const Center(
child: Text("Diese Seite wurde noch nicht entwickelt!!!")),
);
}
}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
google_fonts:
dependency: "direct dev"
description:
name: google_fonts
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.4"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.4"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.16.1 <3.0.0"
flutter: ">=2.10.0-0"
name: deggendorf_app
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.16.1 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.4
http: ^0.13.4
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.4
google_fonts: ^2.3.1
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
assets:
- assets/
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment