This file contains hidden or 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:flutter_riverpod/flutter_riverpod.dart'; | |
void main() => | |
runApp(const ProviderScope(child: MaterialApp(home: HomePage()))); | |
Future<int> calculateSquare(int num) async { | |
await Future.delayed(const Duration(seconds: 2)); | |
return num * num; | |
} |
This file contains hidden or 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
// CopsOnRoad https://stackoverflow.com/questions/50844519/flutter-streambuilder-vs-futurebuilder | |
import 'package:flutter/material.dart'; | |
void main() => runApp(const MaterialApp(home: HomePage())); | |
class HomePage extends StatefulWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override |
This file contains hidden or 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:flutter_app_badger/flutter_app_badger.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import 'package:badges/badges.dart'; | |
// A CustomCounter example implemented with riverpod and shared_preferences | |
// using StateNotifier | |
// using Badges |
This file contains hidden or 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:flutter_riverpod/flutter_riverpod.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
// A CustomCounter example implemented with riverpod and shared_preferences | |
// using StateNotifier | |
class CustomCounter { | |
final int value; | |
final DateTime dateTime; |
This file contains hidden or 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:flutter_riverpod/flutter_riverpod.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
// A Counter example implemented with riverpod and shared_preferences | |
/// Providers are declared globally and specify how to create a state | |
final counterProvider = StateProvider((ref) => 0); | |
final sharedPrefs = Provider<SharedPreferences>((ref) { |
This file contains hidden or 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:flutter_riverpod/flutter_riverpod.dart'; | |
// A Counter example implemented with riverpod | |
void main() { | |
runApp( | |
// Adding ProviderScope enables Riverpod for the entire project | |
const ProviderScope(child: MyApp()), | |
); |