Skip to content

Instantly share code, notes, and snippets.

View Sameerkash's full-sized avatar
🎯
Fluttering with Dart

Sameer Kashyap Sameerkash

🎯
Fluttering with Dart
View GitHub Profile
@Sameerkash
Sameerkash / Code of Conduct.md
Created May 11, 2020 12:33
Code of Conduct for Community

The following guidelines represent the rules to be adhered by wihtin in the community

Please go through them carefully and ensure that you do not violate any of them while being an active member of this group.

Violation of any of these rules will not be tolarated.

  • Usage of language that is obscene will not be allowed or tolerated.

  • No topics relevent to political association, propaganda, or religious matters will be entertained.

@Sameerkash
Sameerkash / Backend
Created June 30, 2020 13:57
Vendor App
http://www.api.tradechat.in/trade-chat/unauth/signup
request
{
"phone":"9945849355",
"isd": "+91"
}
response
{
"id": "8d50a1e0-c406-5d3c-9992-7b8daf827516",
dependencies:
  ...
  state_notifier: ^0.5.0
  flutter_state_notifier: ^0.4.2
  provider: ^4.1.3
  freezed_annotation: ^0.11.0
  ...
  
dev_dependencies:
part 'Todo.freezed.dart';
part 'Todo.g.dart';

@freezed
abstract class Todo with _$Todo {
  const factory Todo(
      {@required String id,
      String title,
 String subtitle,
import '../models/Todo.dart';

part 'todo_state.freezed.dart';

@freezed
abstract class TodoState with _$TodoState {
  const factory TodoState({
    @Default(<Todo>[]) List<Todo> todos,
 }) = TodoStateData;
class TodoVM extends StateNotifier<TodoState> with LocatorMixin {
  TodoVM() : super(const TodoState.loading());
  
class LocalStorage {
  static const DBNAME = "todos";

  final _todosStore = intMapStoreFactory.store();

  Future<Database> get _db async => await AppDatabase.instance.database;


  Future<void> saveTodo(Todo todo) async {
void main() => runApp(
      MultiProvider(
        providers: [
          Provider(
            create: (_) => LocalStorage(),
          ),
          StateNotifierProvider<TodoVM, TodoState>(
            create: (_) => TodoVM(),
 ),
void add(String title, String subtitle) {
  var currentState = state;
  if (currentState == TodoState.empty()) {
    currentState = TodoState();
  }
  //check fot current state
  if (currentState is TodoStateData) {
    //object
final todo = Todo(
// mark a todo as done
void toggle(Todo todo) {
   final currentState = state;
   if (currentState is TodoStateData) {
     final todos = currentState.todos.map((t) {
       if (t == todo) {
         var to = t.copyWith(
           isDone: !t.isDone,
);