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
Doc.fromJson(Map<String, dynamic> json) { | |
date = json['date']; | |
docType = json['doc_type']; | |
title = json['title']; | |
extractedText = json['extracted_text']; | |
summary = json['summary']; | |
author = json['author']; | |
updatedBy = json['updated_by']; | |
} |
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<Doc>> callApi(apiURL) async { | |
try { | |
options.headers['Authorization'] = 'Bearer $accessToken'; | |
Response response = await dio.get(apiURL!); | |
List<dynamic> jsonData = response.data; | |
docs = jsonData.map((user) => Doc.fromJson(user)).toList(); | |
return docs; | |
} catch (e) { | |
rethrow; | |
} |
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
login() async { | |
final userName = dotenv.env['USERNAME']; | |
final password = dotenv.env['PASSWORD']; | |
var response = await dio.post('/api/token/', | |
data: {"username": userName, "password": password}); | |
if (response.statusCode == 200) { | |
final data = response.data; | |
accessToken = data['access']; | |
await storage.write(key: "accessToken", value: accessToken); |
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<bool> refreshToken() async { | |
var refreshToken = await storage.read(key: 'refreshToken'); | |
final response = | |
await dio.post('/api/token/refresh/', data: {'refresh': refreshToken}); | |
if (response.statusCode == 201) { | |
final data = response.data; | |
accessToken = data['access']; | |
await storage.write(key: "accessToken", value: accessToken); | |
return true; |
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<bool> get validAccessToken async { | |
final token = await storage.read(key: "accessToken"); | |
if (token == null || token.isEmpty || Jwt.isExpired(token)) { | |
return false; | |
} else { | |
accessToken = token; | |
return true; | |
} | |
} |
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
const storage = FlutterSecureStorage(); | |
class DocApi { | |
List<Doc> docs = []; | |
String? accessToken; | |
final Dio dio = Dio(); | |
BaseOptions options = BaseOptions(); | |
DocApi() { | |
final baseURL = dotenv.env['BASEURL']; |
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 _MyHomePageState extends State<MyHomePage> { | |
final docapi = DocApi(); | |
List<Doc> docs = []; | |
String searchTerm = ''; | |
List<Doc> filteredItems = []; | |
String _query = ''; | |
void search(String query) { | |
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
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({super.key, required this.title}); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} |
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 DocsApp extends StatelessWidget { | |
const DocsApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
final ThemeData theme = ThemeData(); | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Docs App', | |
theme: theme.copyWith( |
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<void> main() async { | |
await dotenv.load(); | |
runApp(const DocsApp()); | |
} |
NewerOlder