Skip to content

Commit

Permalink
0.3.6+241106 - Minor update
Browse files Browse the repository at this point in the history
- Testing localizations.
- Initialize some screens.
  • Loading branch information
ZoeMeow1027 committed Nov 6, 2024
1 parent f1b0344 commit 3a9d217
Show file tree
Hide file tree
Showing 24 changed files with 600 additions and 136 deletions.
7 changes: 7 additions & 0 deletions assets/lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"appname": "DutSchedule",
"featurenotready": "This function is in development. Check back soon",
"mainview_tab_dashboard": "Dashboard",
"mainview_tab_news": "News",
"mainview_tab_account": "Accounts"
}
7 changes: 7 additions & 0 deletions assets/lang/vi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"appname": "DutSchedule",
"featurenotready": "Tính năng này đang được phát triển. Hãy kiểm tra lại sau.",
"mainview_tab_dashboard": "Tổng quan",
"mainview_tab_news": "Tin tức",
"mainview_tab_account": "Tài khoản"
}
18 changes: 15 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:dutschedule/viewmodel/settings_instance.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';

import 'ui/view_main/main_view.dart';
import 'utils/app_localizations.dart';
import 'utils/custom_scroll_behavior.dart';
import 'viewmodel/account_session_instance.dart';
import 'viewmodel/main_view_model.dart';
Expand All @@ -16,6 +19,7 @@ void main() {
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => SettingsInstance()),
ChangeNotifierProvider(create: (context) => MainViewModel()),
ChangeNotifierProvider(create: (context) => NewsCacheInstance()),
ChangeNotifierProvider(create: (context) => NewsSearchInstance()),
Expand All @@ -29,13 +33,15 @@ void main() {
class MainApplication extends StatelessWidget {
const MainApplication({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
final settingsInstance = Provider.of<SettingsInstance>(context);

return DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) {
return MaterialApp(
title: 'DutSchedule',
locale: settingsInstance.locale,
title: "DutSchedule",
scrollBehavior: CustomScrollBehavior(),
theme: ThemeData(
primarySwatch: lightDynamic != null ? null : Colors.blue,
Expand All @@ -47,6 +53,12 @@ class MainApplication extends StatelessWidget {
colorScheme: darkDynamic,
useMaterial3: true,
),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale("en"),
const Locale("vi"),
Expand All @@ -57,4 +69,4 @@ class MainApplication extends StatelessWidget {
},
);
}
}
}
17 changes: 17 additions & 0 deletions lib/model/news_search_history.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:dutwrapper/enums.dart';

class NewsSearchHistory {
final String query;
final NewsType newsType;
final NewsSearchMethod searchMethod;

const NewsSearchHistory({
required this.query,
required this.newsType,
required this.searchMethod,
});

bool equals(NewsSearchHistory value) {
return query == value.query && newsType == value.newsType && searchMethod == value.searchMethod;
}
}
55 changes: 55 additions & 0 deletions lib/ui/components/listview_group_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:flutter/material.dart';

import '../../utils/theme_tools.dart';

class ListViewGroupItem extends StatelessWidget {
const ListViewGroupItem({
super.key,
this.padding = EdgeInsets.zero,
required this.title,
required this.children,
this.dividerOnBottom = false,
});

final EdgeInsets padding;
final String title;
final List<Widget> children;
final bool dividerOnBottom;

@override
Widget build(BuildContext context) {
return Container(
padding: padding,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: List.generate(
children.length + 2,
(index) {
if (index == 0) {
return Padding(
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 5),
child: Text(
title,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: Theme.of(context).colorScheme.primary,
),
),
);
} else if (index == children.length + 1) {
return dividerOnBottom
? Divider(
color: ThemeTool.isAppDarkMode(context) ? Colors.white : Colors.black,
thickness: 1,
height: 0,
)
: Container();
} else {
return children.elementAt(index - 1);
}
},
),
),
);
}
}
60 changes: 60 additions & 0 deletions lib/ui/components/listview_option_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';

class ListViewOptionItem extends StatelessWidget {
const ListViewOptionItem({
super.key,
required this.title,
this.description,
this.leading,
this.trailing,
this.onClick,
});

final String title;
final String? description;
final Widget? leading;
final Widget? trailing;
final Function()? onClick;

@override
Widget build(BuildContext context) {
return SizedBox(
width: double.infinity,
child: InkWell(
onTap: () {
onClick?.call();
},
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 15, left: 20, right: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
leading != null ? leading! : Container(),
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: leading != null ? 20 : 0,
right: trailing != null ? 15 : 0,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context).textTheme.titleMedium,
),
description != null ? Text(description!) : Container(),
],
),
),
),
trailing != null ? trailing! : Container(),
],
),
),
),
);
}
}
8 changes: 4 additions & 4 deletions lib/ui/components/tab_switch_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ class TabSwitchButton extends StatelessWidget {
},
style: TextButton.styleFrom(
backgroundColor: isFocus
? (ThemeTool.isDarkMode(context)
? (ThemeTool.isAppDarkMode(context)
? Colors.white
: Theme.of(context).primaryColor)
: (ThemeTool.isDarkMode(context)
: (ThemeTool.isAppDarkMode(context)
? Theme.of(context).primaryColor
: Colors.white),
foregroundColor: isFocus
? (ThemeTool.isDarkMode(context)
? (ThemeTool.isAppDarkMode(context)
? Theme.of(context).primaryColor
: Colors.white)
: null,
shape: RoundedRectangleBorder(
side: BorderSide(
color: ThemeTool.isDarkMode(context)
color: ThemeTool.isAppDarkMode(context)
? Colors.white
: Theme.of(context).primaryColor,
width: 1.5,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/components/widget_news/news_detail_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NewsDetailItem extends StatelessWidget {
fontSize: 17,
color: data[index].url != null
? Colors.blueAccent
: ThemeTool.isDarkMode(context)
: ThemeTool.isAppDarkMode(context)
? Colors.white
: Colors.black,
),
Expand Down
49 changes: 27 additions & 22 deletions lib/ui/view_main/main_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:provider/provider.dart';

import '../../main.dart';
import '../../model/scaffold_nav.dart';
import '../../utils/app_localizations.dart';
import '../../utils/get_device_type.dart';
import '../../viewmodel/account_session_instance.dart';
import '../../viewmodel/main_view_model.dart';
import '../../viewmodel/news_cache_instance.dart';
import 'tab_account/account_tab.dart';
import 'tab_dashboard/dashboard_tab.dart';
import 'tab_news/news_tab.dart';

class MainScreenView extends StatefulWidget {
Expand All @@ -19,25 +22,7 @@ class MainScreenView extends StatefulWidget {
}

class _MyHomePageState extends State<MainScreenView> {
int _selectedPage = 1;

final ScaffoldNavigationList _navList = ScaffoldNavigationList(itemList: [
ScaffoldNavigationItem(
id: 0,
label: "Dashboard",
iconData: Icons.home,
),
ScaffoldNavigationItem(
id: 1,
label: "News",
iconData: Icons.newspaper,
),
ScaffoldNavigationItem(
id: 2,
label: "Accounts",
iconData: Icons.account_circle_outlined,
),
]);
int _selectedPage = 0;

late PageController _controller;

Expand Down Expand Up @@ -84,7 +69,7 @@ class _MyHomePageState extends State<MainScreenView> {
screenType.value > DeviceType.phone.value
? NavigationRail(
groupAlignment: 0.0,
destinations: _navList.convertToListNavRailDestination(),
destinations: _getNavList(context).convertToListNavRailDestination(),
selectedIndex: _selectedPage,
labelType: NavigationRailLabelType.all,
onDestinationSelected: (index) {
Expand All @@ -103,7 +88,7 @@ class _MyHomePageState extends State<MainScreenView> {
});
},
children: const <Widget>[
Center(),
DashboardTab(),
NewsTab(),
AccountTab(),
],
Expand All @@ -113,7 +98,7 @@ class _MyHomePageState extends State<MainScreenView> {
),
bottomNavigationBar: screenType.value <= DeviceType.phone.value
? NavigationBar(
destinations: _navList.convertToListNavDestination(),
destinations: _getNavList(context).convertToListNavDestination(),
selectedIndex: _selectedPage,
onDestinationSelected: (index) {
_controller.jumpToPage(index);
Expand All @@ -122,4 +107,24 @@ class _MyHomePageState extends State<MainScreenView> {
: null,
);
}

ScaffoldNavigationList _getNavList(BuildContext context) {
return ScaffoldNavigationList(itemList: [
ScaffoldNavigationItem(
id: 0,
label: AppLocalizations.of(context).translate("mainview_tab_dashboard"),
iconData: Icons.home,
),
ScaffoldNavigationItem(
id: 1,
label: AppLocalizations.of(context).translate("mainview_tab_news"),
iconData: Icons.newspaper,
),
ScaffoldNavigationItem(
id: 2,
label: AppLocalizations.of(context).translate("mainview_tab_account"),
iconData: Icons.account_circle_outlined,
),
]);
}
}
2 changes: 1 addition & 1 deletion lib/ui/view_main/tab_account/not_logged_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AccountNotLoggedInView extends StatelessWidget {
RichText(
text: TextSpan(
style: TextStyle(
color: ThemeTool.isDarkMode(context) ? Colors.white : Colors.black,
color: ThemeTool.isAppDarkMode(context) ? Colors.white : Colors.black,
),
children: [
WidgetSpan(
Expand Down
48 changes: 48 additions & 0 deletions lib/ui/view_main/tab_dashboard/dashboard_tab.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import '../../../utils/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../viewmodel/settings_instance.dart';
import '../../view_settings/settings_view.dart';

class DashboardTab extends StatelessWidget {
const DashboardTab({super.key});

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

return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context).translate("appname")),
actions: [
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SettingsView()),
);
},
icon: const Icon(Icons.settings),
),
],
),
body: Column(
children: [
TextButton(
onPressed: () {
settingsInstance.setLocale(Locale("en", "US"));
},
child: const Text("en-us"),
),
TextButton(
onPressed: () {
settingsInstance.setLocale(Locale("vi"));
},
child: const Text("vi"),
),
],
),
);
}
}
Loading

0 comments on commit 3a9d217

Please sign in to comment.