What's the best practice to keep all the constants in Flutter?

前端 未结 8 480
终归单人心
终归单人心 2021-01-30 02:11

What\'s the best programming practice to

create a constant class in Flutter

to keep all the application constants for easy referenc

8条回答
  •  死守一世寂寞
    2021-01-30 02:44

    I like to organise my "constants" this way. It's easier for me to stay organised and to keep track what's already there. I can than do stuff like this: Tables.questions.id and Tables.anwerOptions.orderIndex

    class Tables {
      static QuestionsTable get questions => QuestionsTable();
      static AnswerOptionsTable get answerOptions => AnswerOptionsTable();
    }
    
    class QuestionsTable {
      String get id => "id";
      String get title => "question";
      String get subtitle => "description";
      String get inputFieldType => "answer_input_type";
      String get answer => "answer";
    }
    
    class AnswerOptionsTable {
      String get id => "id";
      String get questionId => "question_id";
      String get answerOption => "answer_option";
      String get orderIndex => "order_index";
    }
    

提交回复
热议问题