-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from Eldar2021/el-dev-mode
Set dev mode
- Loading branch information
Showing
21 changed files
with
236 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:mq_storage/mq_storage.dart'; | ||
import 'package:my_quran/constants/contants.dart'; | ||
|
||
@immutable | ||
final class AppConfig { | ||
const AppConfig({this.isIntegrationTest = false}); | ||
const AppConfig({ | ||
this.storage, | ||
this.isIntegrationTest = false, | ||
}); | ||
|
||
final bool isIntegrationTest; | ||
|
||
final PreferencesStorage? storage; | ||
|
||
Future<void> setDevMode({required String devDomain, required bool isDevmode}) async { | ||
await storage?.writeString(key: 'dev-domain', value: devDomain); | ||
await storage?.writeBool(key: 'dev-mode', value: isDevmode); | ||
} | ||
|
||
Future<void> clearDevMode() async { | ||
await storage?.delete(key: 'dev-domain'); | ||
await storage?.delete(key: 'dev-mode'); | ||
} | ||
|
||
Future<void> changeJustDevMode({required bool isDevmode}) async { | ||
await storage?.writeBool(key: 'dev-mode', value: isDevmode); | ||
init(); | ||
} | ||
|
||
void init() { | ||
final devDomain = storage?.readString(key: 'dev-domain'); | ||
final isDevmode = storage?.readBool(key: 'dev-mode') ?? false; | ||
apiConst = ApiConst(isDevmode: isDevmode, devDomain: devDomain); | ||
} | ||
} | ||
|
||
ApiConst apiConst = const ApiConst(isDevmode: false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
class ApiConst { | ||
static const domain = 'http://quran.isistant.io/api/v1'; | ||
static const signUp = '$domain/auth/sign_up'; | ||
static const home = '$domain/report/dashboard'; | ||
static const hatim = '$domain/hatim/join_to_hatim'; | ||
|
||
static const appLogoLink = 'https://github.com/Eldar2021/my_quran/blob/main/app/assets/images/app_icon.png?raw=true'; | ||
|
||
static const socketBase = 'ws://quran.isistant.io/ws'; | ||
|
||
static String juzSocket(String hatimId) => '/topic/$hatimId/list_of_juz'; | ||
|
||
static String userPages(String username) => '/topic/$username/user_pages'; | ||
|
||
static String getPagesByJuz(String juzId) => '/topic/$juzId/list_of_page'; | ||
|
||
static const setInProgress = '/app/in_progress'; | ||
static const setBook = '/app/book'; | ||
static const setTodo = '/app/to_do'; | ||
static const setDone = '/app/done'; | ||
|
||
static Map<String, String> authMap(String token) => {'Authorization': 'Bearer $token'}; | ||
|
||
static const urlGitHub = 'https://github.com/Eldar2021/my_quran'; | ||
const ApiConst({ | ||
required this.isDevmode, | ||
this.devDomain, | ||
}); | ||
|
||
final bool isDevmode; | ||
final String? devDomain; | ||
|
||
static const domain = 'quran.isistant.io'; | ||
|
||
String get baseUrl => 'http://$_getDomain/api/v1'; | ||
String get signUp => '$baseUrl/auth/sign_up'; | ||
String get home => '$baseUrl/report/dashboard'; | ||
String get hatim => '$baseUrl/hatim/join_to_hatim'; | ||
|
||
String get baseSocket => 'ws://$_getDomain/ws'; | ||
String juzSocket(String hatimId) => '/topic/$hatimId/list_of_juz'; | ||
String userPages(String username) => '/topic/$username/user_pages'; | ||
String getPagesByJuz(String juzId) => '/topic/$juzId/list_of_page'; | ||
String get setInProgress => '/app/in_progress'; | ||
String get setBook => '/app/book'; | ||
String get setTodo => '/app/to_do'; | ||
String get setDone => '/app/done'; | ||
|
||
Map<String, String> authMap(String token) => {'Authorization': 'Bearer $token'}; | ||
|
||
String get _getDomain { | ||
if (isDevmode && devDomain != null && devDomain!.isNotEmpty) return devDomain!; | ||
return domain; | ||
} | ||
|
||
String verse(int page, String quranFmt) => 'https://api.quran.com/api/v4/quran/verses/$quranFmt?page_number=$page'; | ||
String audio(String surahIndex) => | ||
'https://download.quranicaudio.com/quran/mishaari_raashid_al_3afaasee/$surahIndex.mp3'; | ||
|
||
String get urlGitHub => 'https://github.com/Eldar2021/my_quran'; | ||
// TODO(eldiiar): Replace the privacy policy URL with the actual [URL] of your privacy policy page. | ||
static const provicyPolicy = 'https://github.com/Eldar2021/my_quran'; | ||
|
||
static String verse(int page, String quranFmt) => | ||
'https://api.quran.com/api/v4/quran/verses/$quranFmt?page_number=$page'; | ||
static String audio(String surahIndex) => | ||
'https://download.quranicaudio.com/quran/mishaari_raashid_al_3afaasee/$surahIndex.mp3'; | ||
String get provicyPolicy => 'https://github.com/Eldar2021/my_quran'; | ||
String get appLogoLink => 'https://github.com/Eldar2021/my_quran/blob/main/app/assets/images/app_icon.png?raw=true'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'view/dev_mode_view.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:my_quran/config/app_config.dart'; | ||
import 'package:my_quran/utils/show/alerts.dart'; | ||
|
||
class DevModeView extends StatefulWidget { | ||
const DevModeView({super.key}); | ||
|
||
@override | ||
State<DevModeView> createState() => _DevModeViewState(); | ||
} | ||
|
||
class _DevModeViewState extends State<DevModeView> { | ||
final _controller = TextEditingController(); | ||
bool isDevMode = false; | ||
|
||
@override | ||
void initState() { | ||
_controller.text = apiConst.devDomain ?? ''; | ||
isDevMode = apiConst.isDevmode; | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Enable/Disable dev-mode'), | ||
), | ||
body: ListView( | ||
padding: const EdgeInsets.symmetric(horizontal: 20), | ||
children: [ | ||
const SizedBox(height: 30), | ||
TextFormField(controller: _controller), | ||
const SizedBox(height: 20), | ||
Card( | ||
child: SwitchListTile.adaptive( | ||
title: const Text('Enable/Disable dev-mode'), | ||
value: isDevMode, | ||
onChanged: (v) { | ||
setState(() { | ||
isDevMode = v; | ||
}); | ||
}, | ||
), | ||
), | ||
const SizedBox(height: 40), | ||
ElevatedButton( | ||
onPressed: () async { | ||
final appConfig = context.read<AppConfig>(); | ||
await appConfig.setDevMode( | ||
devDomain: _controller.text, | ||
isDevmode: isDevMode, | ||
); | ||
if (context.mounted) { | ||
AppAlert.showRestartDialog(context); | ||
} | ||
}, | ||
child: const Text('Save'), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.