Activate light and dark theme
parent
5a645f13c0
commit
a8a7b5a613
@ -1,10 +1,15 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:localization/localization.dart';
|
import 'package:localization/localization.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../controllers/providers/settings/setting_provider.dart';
|
||||||
import '../models/enums/translation_keys.dart';
|
import '../models/enums/translation_keys.dart';
|
||||||
|
|
||||||
extension BuildContextExtension on BuildContext {
|
extension BuildContextExtension on BuildContext {
|
||||||
String translate(TranslationKeys translationKey) {
|
String translate(TranslationKeys translationKey) {
|
||||||
return translationKey.name.i18n([Localizations.localeOf(this).toString()]);
|
return translationKey.name.i18n([Localizations.localeOf(this).toString()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get isDark => Provider.of<SettingProvider>(this).theme.brightness == Brightness.dark;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
|
||||||
|
import '../../controllers/providers/api/user_provider.dart';
|
||||||
|
import '../../controllers/providers/settings/setting_provider.dart';
|
||||||
|
import '../../models/enums/translation_keys.dart';
|
||||||
|
import '../app_style/app_themes.dart';
|
||||||
|
import 'app_filled_button.dart';
|
||||||
|
|
||||||
|
class AppDrawer extends StatelessWidget {
|
||||||
|
const AppDrawer({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final settingProvider = Provider.of<SettingProvider>(context, listen: false);
|
||||||
|
final userProvider = Provider.of<UserProvider>(context, listen: false);
|
||||||
|
return Drawer(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
AppFilledButton(
|
||||||
|
label: TranslationKeys.login,
|
||||||
|
onPressed: () async {
|
||||||
|
// bool result = await showDialog(
|
||||||
|
// context: context,
|
||||||
|
// builder: (_) => const AAlertDialog(
|
||||||
|
// title: "_subtitle.signOut",
|
||||||
|
// content: "_subtitle.signOutAlert",
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
if (true) {
|
||||||
|
settingProvider.resetSettings();
|
||||||
|
userProvider.reset();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Switch.adaptive(
|
||||||
|
value: context.isDark,
|
||||||
|
onChanged: (dark) {
|
||||||
|
Provider.of<SettingProvider>(context, listen: false).setTheme(dark ? AppThemes.darkTheme : AppThemes.lightTheme);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
|
||||||
|
import '../../app_style/app_color.dart';
|
||||||
|
|
||||||
|
class DashboardPageIndicator extends StatelessWidget {
|
||||||
|
final PageController controller;
|
||||||
|
final int index, currentPage;
|
||||||
|
const DashboardPageIndicator({
|
||||||
|
Key key,
|
||||||
|
@required this.controller,
|
||||||
|
@required this.index,
|
||||||
|
@required this.currentPage,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final bool isActive = currentPage == (index + 1);
|
||||||
|
return InkWell(
|
||||||
|
onTap: () {
|
||||||
|
controller.animateToPage(index, duration: const Duration(milliseconds: 500), curve: Curves.ease);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
width: (isActive ? 30 : 16).toScreenWidth,
|
||||||
|
height: 9.toScreenHeight,
|
||||||
|
decoration: BoxDecoration(color: isActive ? AppColor.green50 : AppColor.neutral40, borderRadius: BorderRadius.circular(8)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,112 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
|
||||||
|
import '../../common_widgets/app_drawer.dart';
|
||||||
|
import 'dashboard_page_indicator.dart';
|
||||||
|
|
||||||
|
class LandPage extends StatefulWidget {
|
||||||
|
static const String routeName = "/land-page";
|
||||||
|
const LandPage({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<LandPage> createState() => _LandPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LandPageState extends State<LandPage> {
|
||||||
|
PageController _controller;
|
||||||
|
int _currentPage = 1;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = PageController()
|
||||||
|
..addListener(() {
|
||||||
|
_currentPage = _controller.page.toInt() + 1;
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return WillPopScope(
|
||||||
|
onWillPop: () async {
|
||||||
|
// bool result = await showDialog(
|
||||||
|
// context: context,
|
||||||
|
// builder: (_) => const AAlertDialog(
|
||||||
|
// title: "_subtitle.exit",
|
||||||
|
// content: "_subtitle.exitAlert",
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
if (true) {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
|
||||||
|
} else {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: AppBar(),
|
||||||
|
body: Padding(
|
||||||
|
padding: EdgeInsets.only(left: 16.toScreenWidth, top: 11.toScreenHeight),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
DashboardPageIndicator(index: 0, currentPage: _currentPage, controller: _controller),
|
||||||
|
3.width,
|
||||||
|
DashboardPageIndicator(index: 1, currentPage: _currentPage, controller: _controller),
|
||||||
|
3.width,
|
||||||
|
DashboardPageIndicator(index: 2, currentPage: _currentPage, controller: _controller),
|
||||||
|
10.width,
|
||||||
|
Text(
|
||||||
|
"0$_currentPage/03",
|
||||||
|
style: Theme.of(context).textTheme.labelMedium?.copyWith(fontWeight: FontWeight.w500, color: context.isDark ? AppColor.neutral40 : AppColor.neutral60),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
8.height,
|
||||||
|
Expanded(
|
||||||
|
child: PageView(
|
||||||
|
controller: _controller,
|
||||||
|
children: const [
|
||||||
|
Center(
|
||||||
|
child: Text('First Page'),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Text('Second Page'),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Text('Third Page'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
|
items: [
|
||||||
|
BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"),
|
||||||
|
BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"),
|
||||||
|
BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
drawer: const AppDrawer(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue