Skip to content

Commit

Permalink
Merge pull request #244 from sparcs-kaist/feature@/3.24-dark-mode
Browse files Browse the repository at this point in the history
Feature@/3.24 dark mode
  • Loading branch information
thomaskim1130 authored Nov 21, 2024
2 parents 9684f5c + 644ede9 commit f33baed
Show file tree
Hide file tree
Showing 35 changed files with 1,566 additions and 655 deletions.
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"hotNotifications": "Hot Notifications",
"hotPosts": "Hot Posts",
"hotInfo": "We deliver trending announcements and posts every day at 8:30 a.m.",
"emailNotAvailable": "If the default mail application cannot be opened, please contact [email protected]."
"emailNotAvailable": "If the default mail application cannot be opened, please contact [email protected].",
"dark": "Dark Mode"
},
"userPage": {
"change": "Chg.",
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"hotNotifications": "인기 공지글",
"hotPosts": "인기글",
"hotInfo": "인기 공지글 및 인기 글을 매일 오전 8시 30분에 전달해 드립니다.",
"emailNotAvailable": "기본 메일 어플리케이션을 열 수 없습니다. [email protected]로 문의 부탁드립니다."
"emailNotAvailable": "기본 메일 어플리케이션을 열 수 없습니다. [email protected]로 문의 부탁드립니다.",
"dark": "다크 모드"
},
"userPage": {
"change": "수정",
Expand Down
3 changes: 3 additions & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
152 changes: 152 additions & 0 deletions lib/constants/theme_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import 'package:flutter/material.dart';

/// 다크/라이트 모드를 Theme으로 정의합니다
class NewAraThemes {
// DARK THEME SETTINGS
static final darkTheme = ThemeData(
appBarTheme:
const AppBarTheme(elevation: 0, backgroundColor: Color(0xff111111)),
fontFamily: 'Pretendard',
scaffoldBackgroundColor: Color(0xff111111),
splashColor: Colors.transparent,
textSelectionTheme: const TextSelectionThemeData(
cursorColor: Colors.transparent,
),
textTheme: TextTheme(
displayLarge: TextStyle(
color: Colors.white,
),
displayMedium: TextStyle(
color: Colors.white,
),
displaySmall: TextStyle(
color: Colors.white,
),
headlineLarge: TextStyle(
color: Colors.white,
),
headlineMedium: TextStyle(
color: Colors.white,
),
headlineSmall: TextStyle(
color: Colors.white,
),
titleLarge: TextStyle(
color: Colors.white,
),
titleMedium: TextStyle(
color: Colors.white,
),
titleSmall: TextStyle(
color: Colors.white,
),
bodyLarge: TextStyle(
color: Colors.white,
),
bodyMedium: TextStyle(
color: Colors.white,
),
bodySmall: TextStyle(
color: Colors.white,
),
labelLarge: TextStyle(
color: Colors.white,
),
labelMedium: TextStyle(
color: Colors.white,
),
labelSmall: TextStyle(
color: Colors.white,
),
),
);

// LIGHT THEME SETTINGS
static final lightTheme = ThemeData(
appBarTheme:
const AppBarTheme(elevation: 0, backgroundColor: Colors.white),
fontFamily: 'Pretendard',
scaffoldBackgroundColor: Colors.white,
splashColor: Colors.transparent,
textSelectionTheme: const TextSelectionThemeData(
cursorColor: Colors.transparent,
),
textTheme: TextTheme(
displayLarge: TextStyle(
color: Colors.black,
),
displayMedium: TextStyle(
color: Colors.black,
),
displaySmall: TextStyle(
color: Colors.black,
),
headlineLarge: TextStyle(
color: Colors.black,
),
headlineMedium: TextStyle(
color: Colors.black,
),
headlineSmall: TextStyle(
color: Colors.black,
),
titleLarge: TextStyle(
color: Colors.black,
),
titleMedium: TextStyle(
color: Colors.black,
),
titleSmall: TextStyle(
color: Colors.black,
),
bodyLarge: TextStyle(
color: Colors.black,
),
bodyMedium: TextStyle(
color: Colors.black,
),
bodySmall: TextStyle(
color: Colors.black,
),
labelLarge: TextStyle(
color: Colors.black,
),
labelMedium: TextStyle(
color: Colors.black,
),
labelSmall: TextStyle(
color: Colors.black,
),
));

static const Color darkMainText = Color(0xff000000);
static const Color darkInputDecoration = Color(0xFF161616);
static const Color darkInputHint = Color(0xff555555);

static const Color lightInputDecoration = Color(0xFFF6F6F6);
static const Color lightInputHint = Color(0xffbbbbbb);

static const Color gry3 = Color(0xff333333);
static const Color gry5 = Color(0xff555555);
static const Color gryC = Color(0xffcccccc);
static const Color gryB = Color(0xffbbbbbb);
static const Color gry6 = Color(0xff666666);
static const Color lightBRLine = Color(0xfff0f0f0);

static const Color gryB1 = Color(0xffb1b1b1);
static const Color gry61 = Color(0xff616161);

static const Color gryDB = Color(0xffdbdbdb);
static const Color gry36 = Color(0xff363636);

static const Color gryA9 = Color(0xffa9a9a9);
static const Color gry67 = Color(0xff676767);

static const Color gry4A = Color(0xff4a4a4a);
static const Color gryD5 = Color(0xffd5d5d5);

static const Color gry64 = Color(0xff646464);
static const Color gryEB = Color(0xffebebeb);

static const Color darkBRLine = Color(0xff3f3f3f);
}
47 changes: 33 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'package:connectivity_plus/connectivity_plus.dart';

import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:new_ara_app/constants/theme_info.dart';
import 'package:new_ara_app/constants/url_info.dart';
import 'package:new_ara_app/providers/theme_provider.dart';
import 'package:new_ara_app/providers/connectivity_provider.dart';
import 'package:new_ara_app/translations/codegen_loader.g.dart';
import 'package:new_ara_app/utils/cache_function.dart';
import 'package:new_ara_app/utils/global_key.dart';
import 'package:new_ara_app/widgets/loading_indicator.dart';
import 'package:provider/provider.dart';
Expand All @@ -31,13 +35,17 @@ void main() async {
// ex) flutter run --dart-define=ENV=development
// ex) flutter run --dart-define=ENV=production
const String environment =
String.fromEnvironment('ENV', defaultValue: 'development');
String.fromEnvironment('ENV', defaultValue: 'development');
await dotenv.load(fileName: ".env.$environment");

newAraDefaultUrl = dotenv.env['NEW_ARA_DEFAULT_URL']!;
newAraAuthority = dotenv.env['NEW_ARA_AUTHORITY']!;
sparcsSSODefaultUrl = dotenv.env['SPARCS_SSO_DEFAULT_URL']!;

final isDarkMode = await fetchCachedApiData('cache/dark_mode_setting') ??
SchedulerBinding.instance.platformDispatcher.platformBrightness == Brightness.dark;
print(isDarkMode);

// 앱 시작점. 다국어 지원 및 여러 데이터 제공자를 포함한 구조로 설정
runApp(
EasyLocalization(
Expand All @@ -57,7 +65,8 @@ void main() async {
..updateCookie(userProvider.getCookiesToString());
}),
ChangeNotifierProvider(create: (_) => BlockedProvider()),
ChangeNotifierProvider(create: (_) => ConnectivityProvider()),
ChangeNotifierProvider(create: (_) => ThemeProvider()..setTheme(isDarkMode)),
ChangeNotifierProvider(create: (context) => ConnectivityProvider(context.read<ThemeProvider>())),
],
child: const MyApp(),
),
Expand Down Expand Up @@ -88,7 +97,6 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();

// 자동 로그인을 위한 초기 설정
autoLoginByGetCookie(Provider.of<UserProvider>(context, listen: false));

Expand All @@ -98,8 +106,12 @@ class _MyAppState extends State<MyApp> {
blockedProvider.fetchBlockedAnonymousPostID().then((_) {
debugPrint("차단한 글 postid 목록: ${blockedProvider.blockedAnonymousPostIDs}");
});


}



/// 자동 로그인을 위한 메서드
/// secureStorage에서 쿠키를 가져와서 사용자 로그인 상태 확인
void autoLoginByGetCookie(UserProvider userProvider) async {
Expand Down Expand Up @@ -127,17 +139,23 @@ class _MyAppState extends State<MyApp> {

@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);

return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
scaffoldMessengerKey: snackBarKey, //
theme: _setThemeData(),
theme: NewAraThemes.lightTheme,
darkTheme: NewAraThemes.darkTheme,
themeMode: themeProvider.themeMode,
// TODO: CustionScrollBehavior의 역할은?
builder: (context, child) {
final MediaQueryData data = MediaQuery.of(context);
return MediaQuery(

// 시스템 폰트 사이즈에 영향을 받지 않도록 textScaleFactor 지정함

data: data.copyWith(textScaler: const TextScaler.linear(1.0)),
child: ScrollConfiguration(
behavior: CustomScrollBehavior(),
Expand All @@ -148,21 +166,21 @@ class _MyAppState extends State<MyApp> {
home: isLoading == true
? const LoadingIndicator() // 로그인 중에는 로딩 인디케이터 표시
: context.watch<UserProvider>().hasData
? (context
.watch<UserProvider>()
.naUser!
.agree_terms_of_service_at !=
null
? const MainNavigationTabPage()
: const LoginPage())
: const LoginPage());
? (context
.watch<UserProvider>()
.naUser!
.agree_terms_of_service_at !=
null
? const MainNavigationTabPage()
: const LoginPage())
: const LoginPage());
}

// 앱의 전반적인 테마 설정
ThemeData _setThemeData() {
return ThemeData(
appBarTheme:
const AppBarTheme(elevation: 0, backgroundColor: Colors.white),
const AppBarTheme(elevation: 0, backgroundColor: Colors.white),
fontFamily: 'Pretendard',
scaffoldBackgroundColor: Colors.white,
splashColor: Colors.transparent,
Expand All @@ -172,3 +190,4 @@ class _MyAppState extends State<MyApp> {
);
}
}

Loading

0 comments on commit f33baed

Please sign in to comment.