String xml file in Flutter

后端 未结 7 1877
难免孤独
难免孤独 2021-02-01 15:18

In flutter string text are directly set to the TextField widget like:

new Text(\'Hello,  How are you?\')

Is correct way ? or we ca

7条回答
  •  孤城傲影
    2021-02-01 15:39

    I use this method instead of using third party lib. Basically, I create a class that holds those values (string, colors, dimens, etc)

    resources.dart

    import 'dart:ui';
    
    class ResString{
      var data = {
        'url' : 'https://facebook.com/',
        'welcome' : 'Welcome Home',
      };
    
      String get(String key){
        return data[key];
      }
    }
    
    class ResColor{
      var data = {
        'colorPrimary' : 0xff652A04,
        'colorPrimaryDark' : 0xffFFFFFF,
        'colorPrimaryLight' : 0xffF6EDDD,
      };
    
      Color get(String key){
        return Color(data[key]);
      }
    }
    

    To use it, simply call the get method

    main.dart

    import 'package:my_app/resources.dart';
    ...
        return Container(
          color: ResColor().get('colorPrimary')
        );
    ...
    

提交回复
热议问题