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
| //https://stackoverflow.com/questions/50360443/parsing-json-that-has-a-nested-array-of-objects-in-dart | |
| genres = (jsonMap['genres'] as List).map((i) => Genre.fromJson(i)).toList() | |
| ///JSON Data | |
| //{ | |
| // "adult": false, | |
| // "backdrop_path": "/wrqUiMXttHE4UBFMhLHlN601MZh.jpg", | |
| // "belongs_to_collection": null, | |
| // "budget": 120000000, | |
| // "genres": [ | |
| // { |
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
| @override | |
| void dispose() { | |
| subscription.cancel(); | |
| super.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
| @override | |
| void initState() { | |
| super.initState(); | |
| connectivity = Connectivity(); | |
| subscription = | |
| connectivity.onConnectivityChanged.listen((ConnectivityResult result) { | |
| if (result == ConnectivityResult.wifi || result == ConnectivityResult.mobile) { | |
| setState(() {}); | |
| } | |
| }); |
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:connectivity/connectivity.dart'; | |
| ... | |
| Connectivity connectivity; | |
| StreamSubscription<ConnectivityResult> subscription; |
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
| FutureBuilder( | |
| future: getData(), | |
| builder: (BuildContext context, AsyncSnapshot snapshot) { | |
| if (snapshot.hasError) { | |
| return Center(child: Text('Error')); | |
| } | |
| if (snapshot.connectionState == ConnectionState.done) { | |
| var mydata = snapshot.data; | |
| return Center(child: Text('${mydata['data'][0]['email']}')); | |
| } else { |
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
| FutureBuilder( | |
| future: getData(), | |
| builder: (BuildContext context, AsyncSnapshot snapshot) {} | |
| ) |
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
| Future getData() async { | |
| http.Response response = await http.get("https://reqres.in/api/users"); | |
| if (response.statusCode == HttpStatus.ok) { | |
| var result = jsonDecode(response.body); | |
| return result; | |
| } | |
| } |
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:http/http.dart' as http; | |
| ... | |
| FutureBuilder( | |
| builder: (BuildContext context, AsyncSnapshot snapshot) {} | |
| ) |
NewerOlder