This file contains 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
// NonstopIO Interview | |
// | |
// | |
// | |
// | |
// | |
// OBJECTIVE: Display the list of words using the NsCard widget, | |
// where the color of the card will initially be red and green | |
// alternately. On clicking the refresh button, all the red | |
// cards should become green and vice versa. |
This file contains 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
{ | |
"data": [ | |
{ | |
"_id": "567489", | |
"name": "ABC Tech", | |
"location": "Pune" | |
}, | |
{ | |
"_id": "579029", | |
"name": "XYZ Tech", |
This file contains 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 UserModelCtrl { | |
static Future initialDownload() async { | |
var response = await AppApi.get<Map<String, dynamic>>(AppUrls.getUsers); | |
if (response.statusCode == 200) { | |
List data = response.data['results']; | |
var saveStartTime = DateTime.now().millisecondsSinceEpoch; | |
for (var rawUser in data) { | |
var user = UserModel.fromMap(rawUser); |
This file contains 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'; | |
import 'package:best_db_poc/utils/app_keys.dart'; | |
import 'package:hive/hive.dart'; | |
part 'user_model.g.dart'; | |
@HiveType(typeId: 1) | |
class UserModel { | |
@HiveField(0) | |
String gender; |
This file contains 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 AppHiveDb { | |
AppHiveDb._(); | |
static AppHiveDb instance = AppHiveDb._(); | |
Box<UserModel> userBox; | |
Box shared; | |
Future init() async { | |
var _directory = await getApplicationDocumentsDirectory(); | |
Hive | |
..init(_directory.path) |
This file contains 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
static Future<List<UserModel>> getAll() async { | |
var fetchStartTime = DateTime.now().millisecondsSinceEpoch; | |
var rawUsers = await AppSqliteDb.sqliteDb.query(UserModel.tableName); | |
var fetchEndTime = DateTime.now().millisecondsSinceEpoch; | |
appWarning( | |
'Time taken to fetch 1000 users from db: ${fetchEndTime - fetchStartTime}ms'); | |
return rawUsers.map((snap) => UserModel.fromDb(snap)).toList(); | |
} |
This file contains 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
static Future initialDownload() async { | |
var response = await AppApi.get<Map<String, dynamic>>(AppUrls.getUsers); | |
if (response.statusCode == 200) { | |
List data = response.data['results']; | |
var saveStartTime = DateTime.now().millisecondsSinceEpoch; | |
for (var rawUser in data) { | |
var user = UserModel.fromMap(rawUser); | |
await AppSqliteDb.sqliteDb.insert(UserModel.tableName, user.toDb()); | |
} | |
var saveEndTime = DateTime.now().millisecondsSinceEpoch; |
This file contains 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
Map<String, dynamic> toDb() { | |
return { | |
'name_title': name.title, | |
'name_first': name.first, | |
'name_last': name.last, | |
'location_street_name': location.street.name, | |
'location_street_number': location.street.number.toString(), | |
'location_city': location.city, | |
'location_state': location.state, | |
'location_country': location.country, |
This file contains 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:sqflite/sqflite.dart'; | |
import 'package:path/path.dart'; | |
class AppSqliteDb { | |
static Database sqliteDb; | |
static String sqliteDbName = 'db1.db'; | |
static Future init() async { | |
String databasesPath = await getDatabasesPath(); | |
String userDBPath = join(databasesPath, '$sqliteDbName'); | |
sqliteDb = await openDatabase( |
This file contains 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'; | |
import 'package:best_db_poc/service/model_ctrl/user_model_ctrl.dart'; | |
import 'package:best_db_poc/utils/app_keys.dart'; | |
class UserModel { | |
String gender; | |
_Name name; | |
_Location location; | |
String email; |
NewerOlder