Skip to content

Commit 2ba2255

Browse files
committed
add a button to open the blog & check if the theme is dark by system setting
Signed-off-by: Tejas Mehta <[email protected]>
1 parent dbca087 commit 2ba2255

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

lib/main.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:html';
2+
13
import 'package:controller_widgets/controller_widgets.dart';
24
import 'package:flutter/material.dart';
35
import 'package:portfolio/routing/portfolio_route_information_parser.dart';
@@ -9,15 +11,15 @@ void main() {
911
future: SharedPreferences.getInstance(),
1012
builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
1113
if (!snapshot.hasData) return Container();
12-
return ThemeControllerWidget(initiallyIsDark: snapshot.data?.getBool("initialDark") ?? false, child: MyApp(),);
14+
return ThemeControllerWidget(
15+
initiallyIsDark: window.matchMedia('(prefers-color-scheme: dark)').matches,
16+
child: MyApp(),
17+
);
1318
}
1419
));
1520
}
1621

1722
class MyApp extends StatelessWidget {
18-
final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();
19-
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
20-
2123
final ThemeData _lightTheme = ThemeData(
2224
brightness: Brightness.light,
2325
appBarTheme: AppBarTheme(color: Colors.transparent, shadowColor: Colors.transparent, iconTheme: IconThemeData(color: Colors.black)),

lib/routing/portfolio_router_delegate.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/// Made on Saturday, May 01, 2021
33
/// File Name: portfolio_router_delegate.dart
44
5+
import 'dart:html';
6+
57
import 'package:flutter/cupertino.dart';
68
import 'package:flutter/material.dart';
79
import 'package:controller_widgets/controller_widgets.dart';
@@ -78,18 +80,24 @@ class PortfolioRouterDelegate extends RouterDelegate<PortfolioRoutePath>
7880
}
7981

8082
AppBar _createAppbar(BuildContext context) {
83+
bool needsButtons = MediaQuery.of(context).size.width > 500;
8184
return AppBar(
8285
title: Text("Tejas Mehta", style: TextStyle(color: ThemeController.of(context).isDark ? Colors.white : Colors.black),),
8386
actions: [
84-
MediaQuery.of(context).size.width > 500 ? TextButton(
87+
if(needsButtons) TextButton(
8588
onPressed: () => moveAndUpdateRoute(PortfolioRoutePath.about(), false),
8689
child: _createTextTab("About", context)
87-
) : Container(),
90+
),
8891
Padding(padding: EdgeInsets.all(10)),
89-
MediaQuery.of(context).size.width > 500 ? TextButton(
92+
if (needsButtons) TextButton(
9093
onPressed: () => moveAndUpdateRoute(PortfolioRoutePath.projects(), false),
9194
child: _createTextTab("Projects", context)
92-
) : Container(),
95+
),
96+
Padding(padding: EdgeInsets.all(10)),
97+
if (needsButtons) TextButton(
98+
onPressed: _moveToBlog,
99+
child: _createTextTab("Blog", context),
100+
),
93101
Padding(padding: EdgeInsets.all(10)),
94102
IconButton(
95103
icon: Icon(ThemeController.of(context).isDark ? Icons.wb_sunny : Icons.brightness_3), onPressed: () {
@@ -105,6 +113,7 @@ class PortfolioRouterDelegate extends RouterDelegate<PortfolioRoutePath>
105113
children: [
106114
ListTile(title: Text("About"), onTap: () => moveAndUpdateRoute(PortfolioRoutePath.about(), true),),
107115
ListTile(title: Text("Projects"), onTap: () => moveAndUpdateRoute(PortfolioRoutePath.projects(), true),),
116+
ListTile(title: Text("Blog"), onTap: _moveToBlog,)
108117
],
109118
),
110119
);
@@ -127,6 +136,10 @@ class PortfolioRouterDelegate extends RouterDelegate<PortfolioRoutePath>
127136
onPopPage: (_, __) => false,
128137
);
129138

139+
void _moveToBlog() {
140+
window.open("https://blog.tmthecoder.dev","_blank");
141+
}
142+
130143
void moveAndUpdateRoute(PortfolioRoutePath path, bool drawer) {
131144
setNewRoutePath(path);
132145
if (drawer) _scaffoldKey.currentState?.openEndDrawer();

0 commit comments

Comments
 (0)