Tab bar to scroll different location

This commit is contained in:
Konstantin Kollar
2022-09-02 22:38:46 +02:00
parent 1b4b82369b
commit 399a99346b
5 changed files with 174 additions and 129 deletions
+21 -57
View File
@@ -1,9 +1,6 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:wetter/components/compact_weather_data.dart';
import 'package:wetter/components/main_menu.dart';
import 'package:wetter/models/daily_weather_model.dart';
import 'package:wetter/services/brightsky_api_service.dart';
import 'package:wetter/screens/main_weather_view.dart';
void main() => runApp(const MyApp());
@@ -15,25 +12,6 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
SharedPreferences? prefs;
int _daysToLoad = 7;
late Future<List<DailyWeatherModel>> dailyWeather;
@override
void initState() {
super.initState();
initializePreferences();
dailyWeather =
BrightSkyAPI.fetchForecastForTimeRange(DateTime.now(), _daysToLoad);
}
Future<void> initializePreferences() async {
prefs = await SharedPreferences.getInstance();
setState(() {
_daysToLoad = prefs!.getInt("daysToLoad") ?? 7;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
@@ -46,43 +24,29 @@ class _MyAppState extends State<MyApp> {
bodyText2: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
),
),
home: Scaffold(
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Wetter in Harburg'),
title: const Text('Wetter'),
bottom: const TabBar(
tabs: [
Tab(icon: Text("Hamburg")),
Tab(icon: Text("Frankfurt")),
Tab(icon: Text("Freiburg")),
],
),
),
drawer: const NavBar(),
body: RefreshIndicator(
onRefresh: () {
return Future(() {
setState(() {
_daysToLoad = prefs?.getInt("daysToLoad") ?? 7;
dailyWeather = BrightSkyAPI.fetchForecastForTimeRange(
DateTime.now(), _daysToLoad);
});
});
},
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Center(
child: FutureBuilder<List<DailyWeatherModel>>(
future: BrightSkyAPI.fetchForecastForTimeRange(
DateTime.now(), _daysToLoad),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data!
.map((e) => CompactWeatherData(e))
.toList());
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const CircularProgressIndicator();
},
),
),
))),
body: const TabBarView(
children: [
MainWeatherView(53.46, 9.98),
MainWeatherView(50.15, 8.70),
MainWeatherView(47.99, 7.85)
],
),
),
),
);
}
}