# Set Up Local Datastore

Follow the steps to set up sqlite and shared preference which are used to store data locally within the app

# Shared preference

  1. Create folder lib/datastore
  2. Add latest shared_preferences (opens new window) package to pubspec.yaml
  3. Click Pub get on Android Studio
  4. Download shared_pref folder from here (opens new window) and add it inside lib/datastore/ folder
  5. Download configure folder from here (opens new window) and add it inside lib/ folder
  6. Change parameters of AppInfo in lib/configure/app_info.dart
  7. Call Initializer().initialize(); inside main function after WidgetsFlutterBinding.ensureInitialized(); in main.dart



 
 
 
 










void main() async {
  /// Initialize firebase app
  WidgetsFlutterBinding.ensureInitialized();

  /// Initialize packages
  await Initializer().initialize();

  /// Orientation
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  runApp(const MyApp());
}

# Sqlite

  1. Add latest sqflite (opens new window) package to pubspec.yaml
  2. Add compatible path (opens new window) package to pubspec.yaml
  3. Add latest path_provider (opens new window) package to pubspec.yaml
  4. Click Pub get on Android Studio
  5. Download sqlite folder from here (opens new window) and add it inside lib/datastore/ folder
  6. Download data_objects folder from here (opens new window) and add it inside lib/datastore/ folder
  7. Add additional parameters to User class in lib/datastore/data_objects/user.dart if needed, based on your app's requirements. Also add these parameters when you create User table in lib/datastore/sqlite/user.dart
  8. Initialize sqlite in lib/configure/initializer.dart as shown below












 
 
 
 




import '../datastore/sqlite/sqlite.dart';
import '../datastore/shared_pref/shared_pref.dart';

class Initializer {
  initialize() async {
    await initializeDatastore();
  }

  /// Initialize sqlite and shared preferences
  initializeDatastore() async {
    /// Initializes shared_preference
    SharedPref().sharedPrefInit();

    /// Initialize sq-lite
    final db = SqliteDB();
    await db.countTable();
  }
}

  1. When you call await db.countTable(); in previous code, if a database is not present, new database is created. Now we have to add tables to database. Creating sqlite table should be done on Splash Screen by calling SqliteDB().createTables();

10 . You will be creating a splash screen in next step