commit from livecd
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mileograph_flutter/services/apiService.dart';
|
||||
import 'package:mileograph_flutter/services/authservice.dart';
|
||||
import 'package:mileograph_flutter/services/dataService.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'components/login/login.dart';
|
||||
|
||||
late ApiService api;
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
Provider<ApiService>(
|
||||
create: (_) =>
|
||||
ApiService(baseUrl: 'https://dev.mileograph.co.uk/api/v1'),
|
||||
create: (_) {
|
||||
api = ApiService(baseUrl: 'https://dev.mileograph.co.uk/api/v1');
|
||||
return api;
|
||||
},
|
||||
),
|
||||
ChangeNotifierProvider<AuthService>(
|
||||
ChangeNotifierProxyProvider<ApiService, AuthService>(
|
||||
create: (context) => AuthService(api: context.read<ApiService>()),
|
||||
update: (_, api, previous) {
|
||||
return previous ?? AuthService(api: api);
|
||||
},
|
||||
),
|
||||
ProxyProvider<AuthService, void>(
|
||||
update: (_, auth, __) {
|
||||
api.setTokenProvider(() => auth.token);
|
||||
},
|
||||
),
|
||||
ChangeNotifierProxyProvider<ApiService, DataService>(
|
||||
create: (context) => DataService(api: context.read<ApiService>()),
|
||||
update: (_, api, previous) => previous ?? DataService(api: api),
|
||||
),
|
||||
],
|
||||
child: MyApp(),
|
||||
@@ -21,25 +38,29 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
class AppRoot extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<AuthService>(
|
||||
builder: (context, auth, child) {
|
||||
return auth.isLoggedIn
|
||||
? MyHomePage(title: "Mileograph")
|
||||
: LoginScreen();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = context.read<AuthService>();
|
||||
|
||||
Widget fullPage;
|
||||
Widget subPage;
|
||||
if (!auth.isLoggedIn) {
|
||||
fullPage = LoginPage();
|
||||
} else {
|
||||
fullPage = MyHomePage(title: "Mileograph");
|
||||
}
|
||||
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
@@ -48,7 +69,7 @@ class MyApp extends StatelessWidget {
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
//fullPage
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
@@ -58,13 +79,14 @@ class MyApp extends StatelessWidget {
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueGrey),
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.blueGrey,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
),
|
||||
themeMode: ThemeMode.system,
|
||||
home: const MyHomePage(title: 'Mile-O-Graph'),
|
||||
home: AppRoot(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -89,10 +111,41 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int pageIndex = 0;
|
||||
final List<Widget> contentPages = [
|
||||
Dashboard(),
|
||||
Center(child: Text("Calculator Page")),
|
||||
Center(child: Text("Entries Page")),
|
||||
Center(child: Text("Traction Page")),
|
||||
Center(child: Text("Trips Page")),
|
||||
];
|
||||
|
||||
bool loggedIn = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final data = context.read<DataService>();
|
||||
if (data.homepageStats == null) {
|
||||
data.fetchHomepageStats();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget currentPage;
|
||||
|
||||
final data = context.watch<DataService>();
|
||||
|
||||
if (data.homepageStats != null) {
|
||||
currentPage = contentPages[pageIndex];
|
||||
} else {
|
||||
currentPage = Center(
|
||||
child: FilledButton(
|
||||
onPressed: data.fetchHomepageStats,
|
||||
child: Text("Fetch"),
|
||||
),
|
||||
);
|
||||
}
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
@@ -108,10 +161,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
// 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),
|
||||
leading: IconButton(onPressed: null, icon: Icon(Icons.menu)),
|
||||
actions: [
|
||||
IconButton(onPressed: null, icon: Icon(Icons.account_circle)),
|
||||
IconButton(onPressed: null, icon: Icon(Icons.settings)),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
@@ -123,16 +174,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
},
|
||||
destinations: [
|
||||
NavigationDestination(icon: Icon(Icons.home), label: "Home"),
|
||||
NavigationDestination(icon: Icon(Icons.route), label: "Calculator"),
|
||||
NavigationDestination(icon: Icon(Icons.list), label: "Entries"),
|
||||
NavigationDestination(icon: Icon(Icons.train), label: "Traction"),
|
||||
NavigationDestination(icon: Icon(Icons.route), label: "Trips"),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.account_circle),
|
||||
label: "User",
|
||||
),
|
||||
NavigationDestination(icon: Icon(Icons.book), label: "Trips"),
|
||||
],
|
||||
),
|
||||
body: Dashboard(),
|
||||
body: currentPage,
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: null,
|
||||
tooltip: 'New Entry',
|
||||
|
||||
Reference in New Issue
Block a user