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
class ExampleScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return ViewModelProvider<ExampleScreenViewModel>( | |
model: ExampleScreenViewModel(context: context), | |
builder: (ExampleScreenViewModel model) { | |
return Scaffold( | |
backgroundColor: Colors.black45, | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.center, |
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
class ViewModelProvider<T extends BaseViewModel> extends StatelessWidget { | |
final BaseViewModel model; | |
final Widget Function(T model) builder; | |
ViewModelProvider({@required this.builder, @required this.model}); | |
@override | |
Widget build(BuildContext context) { | |
return ChangeNotifierProvider<T>( | |
create: (BuildContext context2) => model, |
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
class ExempleScreenViewModel extends BaseViewModel { | |
// Values | |
String mainTitle = 'Flutter Provider & ChangeNotifier Starter'; | |
int resourcesCount; | |
int counter = 0; | |
SplashScreenViewModel({@required BuildContext context}) : super(context: context) { | |
resourcesCount = resourcesProvider.count; | |
} | |
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
class BaseViewModel extends ChangeNotifier { | |
final BuildContext context; | |
AuthenticationProvider authenticationProvider; | |
ResourcesProvider resourcesProvider; | |
ChatProvider chatProvider; | |
BaseViewModel({@required this.context}) { | |
authenticationProvider = Provider.of<AuthenticationProvider>(context); | |
resourcesProvider = Provider.of<ResourcesProvider>(context); |
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
abstract class BaseProvider { | |
AuthenticationProvider authenticationProvider; | |
BaseProvider({@required this.authenticationProvider}); | |
void dispose() {} | |
} |
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
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
SystemChrome.setPreferredOrientations([ | |
DeviceOrientation.portraitUp, | |
]); | |
return Provider<AuthenticationProvider>( |
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:bloc_provider/bloc_provider.dart'; | |
import 'package:flare_flutter/flare_actor.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_svg/svg.dart'; | |
import 'package:location/location.dart'; | |
import 'package:sensors/sensors.dart'; | |
import 'package:http/http.dart' as http; | |
import 'dart:convert' as c; | |
import 'package:rxdart/rxdart.dart'; |
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
class AQ { | |
var city; | |
var aqi; | |
var cat; | |
var reco; | |
var color; | |
var asset; | |
AQ.fJ(j) | |
: aqi = j['data']['indexes']['baqi']['aqi'], |