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
// Production | |
Get.lazyPut<MyService>(() => MyServiceImpl()); | |
// Test | |
Get.lazyPut<MyService>(() => MyServiceMock()); | |
// Call - same for either Production or Test | |
MyService.to.multiply(count1.value, count.value); | |
abstract class MyService { | |
static MyService get to => Get.find(); |
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
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; //STEP 1 - import Get | |
void main() { | |
//STEP 3 - add our services - immediate or lazy | |
Get.put(TestService()); | |
Get.lazyPut<AuthService>(() => AuthService()); | |
runApp(MyApp()); | |
} |
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
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; //STEP 4 - Import shared_preferences | |
void main() { | |
Get.lazyPut<ThemeController>( | |
() => ThemeController()); //STEP 5 - lazy create ThemeController | |
runApp(MyApp()); | |
} |
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
class ThemeController extends GetController { | |
static ThemeController get to => Get.find(); | |
SharedPreferences prefs; | |
ThemeMode _themeMode; | |
ThemeMode get themeMode => _themeMode; | |
Future<void> setThemeMode(ThemeMode themeMode) async { | |
Get.changeThemeMode(themeMode); | |
_themeMode = themeMode; |
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
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
ThemeMode _themeMode = ThemeMode.system; |
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
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
//STEP 2 - replace MaterialApp with GetMaterialApp | |
return GetMaterialApp( | |
title: 'Theme change using Get', | |
theme: ThemeData.light().copyWith(primaryColor: Colors.green), | |
darkTheme: ThemeData.dark().copyWith(primaryColor: Colors.purple), | |
// NOTE: Optional - use themeMode to specify the startup theme | |
themeMode: ThemeMode.system, |
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
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; //STEP 1 - import Get | |
void main() { | |
runApp(MyApp()); | |
} |