Skip to content

Commit

Permalink
Switched to named routes
Browse files Browse the repository at this point in the history
  • Loading branch information
prijindal committed May 6, 2024
1 parent db3ff71 commit d7f60cf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
9 changes: 8 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import './firebase_options.dart';
import './helpers/logger.dart';
import './models/theme.dart';
import './pages/home.dart';
import 'pages/login.dart';
import 'pages/profile.dart';

void main() async {
runApp(
Expand Down Expand Up @@ -45,10 +47,15 @@ class MyMaterialApp extends StatelessWidget {
final themeNotifier = Provider.of<ThemeModeNotifier>(context);
AppLogger.instance.d("Building MyApp");
return MaterialApp(
routes: {
"/": (context) => const MyHomePage(),
"/profile": (context) => const ProfileScreen(),
"/login": (context) => const LoginScreen(),
},
initialRoute: "/",
theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
darkTheme: ThemeData.dark(useMaterial3: true),
themeMode: themeNotifier.getTheme(),
home: const MyHomePage(),
);
}
}
16 changes: 2 additions & 14 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import '../helpers/sync.dart';
import '../models/core.dart';
import '../models/drift.dart';
import '../pages/habbit.dart';
import '../pages/login.dart';
import '../pages/profile.dart';

const mediaBreakpoint = 700;

Expand Down Expand Up @@ -91,12 +89,7 @@ class _MyHomePageState extends State<MyHomePage> {
action: SnackBarAction(
label: "Login",
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => const LoginScreen(),
),
);
Navigator.pushNamed(context, "/login");
await _syncDb();
},
),
Expand Down Expand Up @@ -239,12 +232,7 @@ class _MyHomePageState extends State<MyHomePage> {
padding: const EdgeInsets.only(right: 20.0),
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => const ProfileScreen(),
),
);
Navigator.pushNamed(context, "/profile");
},
child: const Icon(
Icons.person,
Expand Down
8 changes: 1 addition & 7 deletions lib/pages/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:provider/provider.dart';

import '../helpers/sync.dart';
import '../models/theme.dart';
import '../pages/login.dart';

class ProfileScreen extends StatelessWidget {
const ProfileScreen({super.key});
Expand Down Expand Up @@ -287,12 +286,7 @@ class _ProfileAuthTileState extends State<ProfileAuthTile> {
"Login",
),
onTap: () async {
await Navigator.push<UserCredential?>(
context,
MaterialPageRoute(
builder: (context) => const LoginScreen(),
),
);
await Navigator.pushNamed<UserCredential?>(context, "/login");
},
);
}
Expand Down
21 changes: 12 additions & 9 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:habbit_tracker/components/listentries.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
// await tester.pumpWidget(
// const MaterialApp(
// home: Scaffold(
// body: ListEntriesSubPage(
// entries: [],
// ),
// ),
// ),
// );
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ListEntriesSubPage(
entries: [],
habbit: "",
),
),
),
);
});
}

0 comments on commit d7f60cf

Please sign in to comment.