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
private fun launchActivity() { | |
pbLaunching.show() | |
lifecycleScope.launch(Dispatchers.IO) { | |
delay(2000) | |
Log.d("###", "Launching") | |
launch(Dispatchers.Main) { | |
pbLaunching.hid() | |
} | |
} | |
} |
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 ExcerciseViewModel: BaseViewModel() { | |
val listExercise: LiveData<List<Excercise>?> = Transformations.map(repository.allExcercise) { | |
it | |
} | |
private fun handleGetData() { | |
if (!hasDataLocal) { | |
getDataFromFireBase() | |
} | |
} |
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
fun hideKeyboard(activity: Activity) { | |
val inputMethodManager = activity.getSystemSSservice(Activity.INPUT_METHOD_SERVICE) as? InputMethodManager | |
val view = activity.currentFocus ?: View(activity) | |
inputMethodManager?.hideSoftInputFromWindow(view.windowToken, 0) | |
} |
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
_showAddNoteDialog(BuildContext context) => showDialog( | |
context: context, | |
builder: (context) { | |
return AlertDialog( | |
title: Text("Add your note"), | |
content: SingleChildScrollView( | |
child: Container( | |
width: double.infinity, | |
child: Column( | |
mainAxisSize: MainAxisSize.min, |
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
_showMultiChoiceDialog(BuildContext context) => showDialog( | |
context: context, | |
builder: (context) { | |
final _multipleNotifier = Provider.of<MultipleNotifier>(context); | |
return AlertDialog( | |
title: Text("Select one country or many countries"), | |
content: SingleChildScrollView( | |
child: Container( | |
width: double.infinity, | |
child: Column( |
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
void main() { | |
runApp(MultiProvider( | |
providers: [ | |
ChangeNotifierProvider<SingleNotifier>( | |
create: (_) => SingleNotifier(), | |
), | |
ChangeNotifierProvider<MultipleNotifier>( | |
create: (_) => MultipleNotifier([]), | |
) | |
], |
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 MultipleNotifier extends ChangeNotifier { | |
List<String> _selectedItems; | |
MultipleNotifier(this._selectedItems); | |
List<String> get selectedItems => _selectedItems; | |
bool isHaveItem(String value) => _selectedItems.contains(value); | |
addItem(String value) { | |
if (!isHaveItem(value)) { | |
_selectedItems.add(value); | |
notifyListeners(); | |
} |
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
_showSingleChoiceDialog(BuildContext context) => showDialog( | |
context: context, | |
builder: (context) { | |
var _singleNotifier = Provider.of<SingleNotifier>(context); | |
return AlertDialog( | |
title: Text("Select one country"), | |
content: SingleChildScrollView( | |
child: Container( | |
width: double.infinity, | |
child: Column( |
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:examples_dialogs/data.dart'; | |
import 'package:flutter/material.dart'; | |
class SingleNotifier extends ChangeNotifier { | |
String _currentCountry = countries[0]; | |
SingleNotifier(); | |
String get currentCountry => _currentCountry; | |
updateCountry(String value) { | |
if (value != _currentCountry) { | |
_currentCountry = value; | |
notifyListeners(); |
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
_showMessageDialog(BuildContext context) => showDialog( | |
context: context, | |
builder: (context) => AlertDialog( | |
title: Text("Are you sure"), | |
content: Text("Do you want to delete these items?"), | |
actions: <Widget>[ | |
FlatButton( | |
child: Text("Yes"), | |
onPressed: () { | |
Navigator.of(context).pop(); |
NewerOlder