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

前端 未结 8 482
终归单人心
终归单人心 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:40

    For all constants, just create constants.dart file under lib folder or lib/util folder, then keep all constant variables as follows :

     const SUCCESS_MESSAGE=" You will be contacted by us very soon.";
    
     // Api related 
     const apiBaseURL = "https://baseurl.com";
        
     const userLoginApi = "login";
     const userSignupApi = "signup";
        
     // Shared Preference keys 
     const kDeviceName = "device_name";
     const kDeviceUDID = "device_id";
    
     // Asset Constants
     const navBarLogoImage = "assets/images/home_images/sample.png
       
    

    then import constants.dart file in required class and use it directly.

提交回复
热议问题