No Description

main.dart.rtf 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. {\rtf1\ansi\ansicpg1252\cocoartf2577
  2. \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;\f1\fnil\fcharset0 Menlo-Italic;}
  3. {\colortbl;\red255\green255\blue255;\red191\green100\blue38;\red32\green32\blue32;\red88\green118\blue71;
  4. \red254\green187\blue91;\red153\green168\blue186;\red173\green169\blue32;\red133\green96\blue154;\red86\green132\blue173;
  5. }
  6. {\*\expandedcolortbl;;\csgenericrgb\c74902\c39216\c14902;\csgenericrgb\c12549\c12549\c12549;\csgenericrgb\c34510\c46275\c27843;
  7. \csgenericrgb\c99608\c73333\c35686;\csgenericrgb\c60000\c65882\c72941;\csgenericrgb\c67843\c66275\c12549;\csgenericrgb\c52157\c37647\c60392;\csgenericrgb\c33725\c51765\c67843;
  8. }
  9. \margl1440\margr1440\vieww11520\viewh8400\viewkind0
  10. \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
  11. \f0\fs24 \cf2 \cb3 import \cf4 'package:flutter/material.dart'\cf2 ;\
  12. import \cf4 'package:userstory2translate/localization/localization.dart'\cf2 ;\
  13. import \cf4 'package:userstory2translate/router/custom_router.dart'\cf2 ;\
  14. import \cf4 'package:userstory2translate/router/route_constants.dart'\cf2 ;\
  15. import \cf4 'package:flutter_localizations/flutter_localizations.dart'\cf2 ;\
  16. \
  17. import \cf4 'localization/language_constants.dart'\cf2 ;\
  18. \
  19. void \cf5 main\cf6 () => runApp(\cf5 MyApp\cf6 ())\cf2 ;\
  20. \
  21. class \cf6 MyApp \cf2 extends \cf6 StatefulWidget \{\
  22. \cf2 const \cf6 MyApp(\{Key key\}) : \cf2 super\cf6 (key: key)\cf2 ;\
  23. static void
  24. \f1\i \cf5 setLocale
  25. \f0\i0 \cf6 (BuildContext context\cf2 , \cf6 Locale newLocale) \{\
  26. _MyAppState state = context.findAncestorStateOfType<_MyAppState>()\cf2 ;\
  27. \cf6 state.setLocale(newLocale)\cf2 ;\
  28. \cf6 \}\
  29. \
  30. \cf7 @override\
  31. \cf6 _MyAppState \cf5 createState\cf6 () => \cf5 _MyAppState\cf6 ()\cf2 ;\
  32. \cf6 \}\
  33. \
  34. \cf2 class \cf6 _MyAppState \cf2 extends \cf6 State<MyApp> \{\
  35. Locale \cf8 _locale\cf2 ;\
  36. \cf5 setLocale\cf6 (Locale locale) \{\
  37. setState(() \{\
  38. \cf8 _locale \cf6 = locale\cf2 ;\
  39. \cf6 \})\cf2 ;\
  40. \cf6 \}\
  41. \
  42. \cf7 @override\
  43. \cf2 void \cf5 didChangeDependencies\cf6 () \{\
  44. getLocale().then((locale) \{\
  45. setState(() \{\
  46. \cf2 this\cf6 .\cf8 _locale \cf6 = locale\cf2 ;\
  47. \cf6 \})\cf2 ;\
  48. \cf6 \})\cf2 ;\
  49. super\cf6 .didChangeDependencies()\cf2 ;\
  50. \cf6 \}\
  51. \
  52. \cf7 @override\
  53. \cf6 Widget \cf5 build\cf6 (BuildContext context) \{\
  54. \cf2 if \cf6 (\cf2 this\cf6 .\cf8 _locale \cf6 == \cf2 null\cf6 ) \{\
  55. \cf2 return \cf5 Container\cf6 (\
  56. child: \cf5 Center\cf6 (\
  57. child: \cf5 CircularProgressIndicator\cf6 (\
  58. valueColor: \cf5 AlwaysStoppedAnimation\cf6 <Color>(Colors.
  59. \f1\i \cf8 blue
  60. \f0\i0 \cf6 [\cf9 800\cf6 ]))\cf2 ,\
  61. \cf6 )\cf2 ,\
  62. \cf6 )\cf2 ;\
  63. \cf6 \} \cf2 else \cf6 \{\
  64. \cf2 return \cf5 MaterialApp\cf6 (\
  65. debugShowCheckedModeBanner: \cf2 false,\
  66. \cf6 title: \cf4 "Flutter Localization Demo"\cf2 ,\
  67. \cf6 theme: \cf5 ThemeData\cf6 (primarySwatch: Colors.
  68. \f1\i \cf8 blue
  69. \f0\i0 \cf6 )\cf2 ,\
  70. \cf6 locale: \cf8 _locale\cf2 ,\
  71. \cf6 supportedLocales: [\
  72. \cf5 Locale\cf6 (\cf4 "en"\cf2 , \cf4 "US"\cf6 )\cf2 ,\
  73. \cf5 Locale\cf6 (\cf4 "fa"\cf2 , \cf4 "IR"\cf6 )\cf2 ,\
  74. \cf5 Locale\cf6 (\cf4 "es"\cf2 , \cf4 "SP"\cf6 )\cf2 ,\
  75. \cf5 Locale\cf6 (\cf4 "hi"\cf2 , \cf4 "IN"\cf6 )\
  76. ]\cf2 ,\
  77. \cf6 localizationsDelegates: [\
  78. DemoLocalization.
  79. \f1\i \cf8 delegate
  80. \f0\i0 \cf2 ,\
  81. \cf6 GlobalMaterialLocalizations.
  82. \f1\i \cf8 delegate
  83. \f0\i0 \cf2 ,\
  84. \cf6 GlobalWidgetsLocalizations.
  85. \f1\i \cf8 delegate
  86. \f0\i0 \cf2 ,\
  87. \cf6 GlobalCupertinoLocalizations.
  88. \f1\i \cf8 delegate
  89. \f0\i0 \cf2 ,\
  90. \cf6 ]\cf2 ,\
  91. \cf6 localeResolutionCallback: (locale\cf2 , \cf6 supportedLocales) \{\
  92. \cf2 for \cf6 (\cf2 var \cf6 supportedLocale \cf2 in \cf6 supportedLocales) \{\
  93. \cf2 if \cf6 (supportedLocale.\cf8 languageCode \cf6 == locale.\cf8 languageCode \cf6 &&\
  94. supportedLocale.\cf8 countryCode \cf6 == locale.\cf8 countryCode\cf6 ) \{\
  95. \cf2 return \cf6 supportedLocale\cf2 ;\
  96. \cf6 \}\
  97. \}\
  98. \cf2 return \cf6 supportedLocales.\cf8 first\cf2 ;\
  99. \cf6 \}\cf2 ,\
  100. \cf6 onGenerateRoute: CustomRouter.
  101. \f1\i \cf5 generatedRoute
  102. \f0\i0 \cf2 ,\
  103. \cf6 initialRoute: homeRoute\cf2 ,\
  104. \cf6 )\cf2 ;\
  105. \cf6 \}\
  106. \}\
  107. \}\
  108. }