Skip to content

Commit

Permalink
➕ firebase_remote_config
Browse files Browse the repository at this point in the history
Hijri offset data now fetched from the server #54
  • Loading branch information
iqfareez committed Jul 23, 2021
1 parent b500e4c commit f8a0fb1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 65 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class MyHomePage extends StatelessWidget {
bottomNavigationBar: const MyBottomAppBar(),
floatingActionButton: const ShareFAB(),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
body: SingleChildScrollView(child: AppBody()),
body: const SingleChildScrollView(child: AppBody()),
);
}
}
Expand Down
30 changes: 5 additions & 25 deletions lib/views/Settings part/SettingsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,12 @@ class _SettingsPageState extends State<SettingsPage> {
}

Card buildHijriOffset(SettingProvider setting) {
return Card(
return const Card(
child: ListTile(
title: const Text('Hijri date offset'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
style: TextButton.styleFrom(
minimumSize: const Size(5, 5),
backgroundColor: CupertinoColors.tertiarySystemFill),
onPressed: setting.hijriOffset <= -2
? null
: () => setting.hijriOffset--,
child: const FaIcon(FontAwesomeIcons.minus, size: 11)),
Text(
'${setting.hijriOffset} ${setting.hijriOffset == 1 ? 'day' : 'days'}'),
TextButton(
style: TextButton.styleFrom(
minimumSize: const Size(5, 5),
backgroundColor: CupertinoColors.tertiarySystemFill),
onPressed: setting.hijriOffset >= 2
? null
: () => setting.hijriOffset++,
child: const FaIcon(FontAwesomeIcons.plus, size: 11)),
],
),
title: Text('Hijri date offset'),
isThreeLine: true,
subtitle: Text(
'Data will be fetched automatically from the server. Will remove this setting in future updates.'),
),
);
}
Expand Down
9 changes: 0 additions & 9 deletions lib/views/Settings part/settingsProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ class SettingProvider with ChangeNotifier {
bool _isDeveloperOption = GetStorage().read(kDiscoveredDeveloperOption);
int _sharingFormat = GetStorage().read(kSharingFormat);
double _fontSize = GetStorage().read(kFontSize);
int _hijriOffset = GetStorage().read(kHijriOffset);

set hijriOffset(int value) {
_hijriOffset = value;
GetStorage().write(kHijriOffset, value);
notifyListeners();
}

int get hijriOffset => _hijriOffset;

set prayerFontSize(double newValue) {
_fontSize = newValue;
Expand Down
93 changes: 64 additions & 29 deletions lib/views/appBody.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get_storage/get_storage.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hijri/hijri_calendar.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:waktusolatmalaysia/CONSTANTS.dart';
import '../locationUtil/locationDatabase.dart';
import '../locationUtil/location_provider.dart';
import '../utils/sizeconfig.dart';
import 'GetPrayerTime.dart';
import 'Settings%20part/settingsProvider.dart';
import 'ZoneChooser.dart';

class AppBody extends StatelessWidget {
AppBody({Key key}) : super(key: key);
const AppBody({Key key}) : super(key: key);

final _dayFormat = DateFormat('EEEE').format(DateTime.now());
final _dateFormat = DateFormat('dd MMM yyyy').format(DateTime.now());
Future<RemoteConfig> fetchRemoteConfig() async {
final RemoteConfig remoteConfig = RemoteConfig.instance;
await remoteConfig.setConfigSettings(RemoteConfigSettings(
fetchTimeout: const Duration(seconds: 8),
minimumFetchInterval: const Duration(hours: 12),
));
// RemoteConfigValue(null, ValueSource.valueStatic);
await remoteConfig.fetchAndActivate();
return remoteConfig;
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -52,32 +62,25 @@ class AppBody extends StatelessWidget {
color: Colors.white.withAlpha(70),
borderRadius: BorderRadius.circular(8.0),
),
child: Consumer<SettingProvider>(
builder: (context, setting, child) {
var _hijriToday = HijriCalendar.fromDate(
DateTime.now().add(
Duration(days: setting.hijriOffset)));
return Column(
children: [
Text(
_dayFormat,
style: GoogleFonts.spartan(
color: Colors.white),
),
AutoSizeText(
_hijriToday.toFormat("dd MMMM yyyy"),
style: GoogleFonts.acme(
color: Colors.white, fontSize: 17),
stepGranularity: 1,
),
Text(
_dateFormat,
style: TextStyle(
color: Colors.teal.shade100,
fontSize: 12),
child: FutureBuilder<RemoteConfig>(
future: fetchRemoteConfig(),
builder: (context,
AsyncSnapshot<RemoteConfig> snapshot) {
/// Fetch data from server whenever possible
if (snapshot.hasData) {
int _offset =
snapshot.data.getInt('hijri_offset');
GetStorage().write(kHijriOffset, _offset);
return DateWidget(
hijriOffset: Duration(days: _offset),
);
} else {
return DateWidget(
hijriOffset: Duration(
days: GetStorage().read(kHijriOffset),
),
],
);
);
}
},
),
),
Expand Down Expand Up @@ -162,3 +165,35 @@ class AppBody extends StatelessWidget {
);
}
}

class DateWidget extends StatelessWidget {
const DateWidget({
Key key,
@required Duration hijriOffset,
}) : _hijriOffset = hijriOffset,
super(key: key);

final Duration _hijriOffset;

@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
DateFormat('EEEE').format(DateTime.now()),
style: GoogleFonts.spartan(color: Colors.white),
),
AutoSizeText(
HijriCalendar.fromDate(DateTime.now().add(_hijriOffset))
.toFormat("dd MMMM yyyy"),
style: GoogleFonts.acme(color: Colors.white, fontSize: 17),
stepGranularity: 1,
),
Text(
DateFormat('dd MMM yyyy').format(DateTime.now()),
style: TextStyle(color: Colors.teal.shade100, fontSize: 12),
),
],
);
}
}
16 changes: 15 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ packages:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.4.0"
firebase_core_platform_interface:
dependency: transitive
description:
Expand All @@ -162,6 +162,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
firebase_remote_config:
dependency: "direct main"
description:
name: firebase_remote_config
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.0+3"
firebase_remote_config_platform_interface:
dependency: transitive
description:
name: firebase_remote_config_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0+3"
flutter:
dependency: "direct main"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
firebase_core: ^1.0.2
email_validator: ^2.0.1
introduction_screen: ^2.1.0
firebase_remote_config: ^0.10.0+3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit f8a0fb1

Please sign in to comment.