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:google_sign_in/google_sign_in.dart'; | |
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart'; | |
void signInWithGoogle() async { | |
GoogleSignIn _googleSignIn = GoogleSignIn(scopes: ['email']); | |
try { | |
await _googleSignIn.signIn(); | |
// User is signed in, proceed with your app logic |
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
dependencies: | |
flutter: | |
sdk: flutter | |
google_sign_in: ^6.1.0 # Use the latest version from pub.dev | |
flutter_facebook_auth: ^5.0.1 # Use the latest version from pub.dev |
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
dependencies: | |
flutter: | |
sdk: flutter | |
flutter_secure_storage: ^5.0.2 # Use the latest version from pub.dev | |
shared_preferences: ^2.0.7 # Use the latest version from pub.dev |
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<List<Item>> fetchItems() async { | |
final response = await http.get(Uri.parse('https://api.example.com/items')); | |
if (response.statusCode == 200) { | |
// Parse JSON data and return a list of items | |
List<dynamic> jsonResponse = json.decode(response.body); | |
return jsonResponse.map((item) => Item.fromJson(item)).toList(); | |
} else { | |
// Handle errors | |
throw Exception('Failed to load items'); | |
} |
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 'dart:convert'; | |
void parseJson(String jsonData) { | |
Map<String, dynamic> data = json.decode(jsonData); | |
String name = data['name']; | |
int age = data['age']; | |
print('Name: $name, Age: $age'); | |
} |
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; | |
Future<void> fetchData() async { | |
final response = await http.get(Uri.parse('https://api.example.com/data')); | |
if (response.statusCode == 200) { | |
// Handle successful response | |
print('Response data: ${response.body}'); | |
} else { | |
// Handle errors | |
print('Request failed with status: ${response.statusCode}'); |
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_secure_storage/flutter_secure_storage.dart'; | |
final storage = FlutterSecureStorage(); | |
// Storing sensitive data securely | |
await storage.write(key: 'token', value: 'your_auth_token'); | |
// Retrieving data | |
String? token = await storage.read(key: 'token'); |