Committed by
GitHub
Merge pull request #2855 from aratheunseen/master
Add README for Bengali Language (README-bn.md)
Showing
2 changed files
with
1178 additions
and
0 deletions
README-bn.md
0 → 100644
1 | + | ||
2 | + | ||
3 | +[](https://pub.dev/packages/get) | ||
4 | +[](https://pub.dev/packages/get/score) | ||
5 | +[](https://pub.dev/packages/get/score) | ||
6 | +[](https://pub.dev/packages/get/score) | ||
7 | + | ||
8 | +[](https://pub.dev/packages/effective_dart) | ||
9 | +[](https://discord.com/invite/9Hpt99N) | ||
10 | +[](https://communityinviter.com/apps/getxworkspace/getx) | ||
11 | +[](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g) | ||
12 | +<a href="https://github.com/Solido/awesome-flutter"> | ||
13 | +<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" /> | ||
14 | +</a> | ||
15 | +<a href="https://www.buymeacoffee.com/jonataslaw" target="_blank"><img src="https://i.imgur.com/aV6DDA7.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important; box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" > </a> | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | + | ||
20 | +- [Get সম্পর্কে](#about-get) | ||
21 | +- [ইনস্টল](#installing) | ||
22 | +- [GetX দিয়ে কাউন্টার অ্যাপ](#counter-app-with-getx) | ||
23 | +- [GetX এর তিনটি স্তম্ভ](#the-three-pillars) | ||
24 | + - [স্টেট ব্যবস্থাপনা](#state-management) | ||
25 | + - [প্রতিক্রিয়াশীল স্টেট ম্যানেজার](#reactive-state-manager) | ||
26 | + - [স্টেট ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত](#more-details-about-state-management) | ||
27 | + - [রুট ব্যবস্থাপনা](#route-management) | ||
28 | + - [রুট ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত](#more-details-about-route-management) | ||
29 | + - [ডিপেনডেন্সি ব্যবস্থাপনা](#dependency-management) | ||
30 | + - [ডিপেনডেন্সি ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত](#more-details-about-dependency-management) | ||
31 | +- [ইউটিলিটি](#utils) | ||
32 | + - [আন্তর্জাতিকীকরণ](#internationalization) | ||
33 | + - [অনুবাদ](#translations) | ||
34 | + - [অনুবাদের ব্যবহার](#using-translations) | ||
35 | + - [লোকেল](#locales) | ||
36 | + - [লোকেল পরিবর্তন করুন](#change-locale) | ||
37 | + - [লোকেল পদ্ধতি](#system-locale) | ||
38 | + - [থিম পরিবর্তন করুন](#change-theme) | ||
39 | + - [গেট কানেক্ট](#getconnect) | ||
40 | + - [ডিফল্ট কনফিগারেশন](#default-configuration) | ||
41 | + - [কাস্টম কনফিগারেশন](#custom-configuration) | ||
42 | + - [গেট পেজ মিডিলওয়্যার](#getpage-middleware) | ||
43 | + - [অগ্রাধিকার](#priority) | ||
44 | + - [পুনঃনির্দেশ](#redirect) | ||
45 | + - [অন-পেজ কলড](#onpagecalled) | ||
46 | + - [অন-বাইন্ডিং স্টার্ট](#onbindingsstart) | ||
47 | + - [অন-পেজ বিল্ড স্টার্ট](#onpagebuildstart) | ||
48 | + - [অন-পেজ বিল্ড](#onpagebuilt) | ||
49 | + - [অন-পেজ ডিসপোজ](#onpagedispose) | ||
50 | + - [অন্যান্য এপিআই সমূহ](#other-advanced-apis) | ||
51 | + - [ঐচ্ছিক গ্লোবাল সেটিংস এবং ম্যানুয়াল কনফিগারেশন](#optional-global-settings-and-manual-configurations) | ||
52 | + - [লোকাল স্টেট উইজেট](#local-state-widgets) | ||
53 | + - [ভ্যালু বিল্ডার](#valuebuilder) | ||
54 | + - [অব এক্স ভ্যালু](#obxvalue) | ||
55 | + - [প্রয়োজনীয় পরামর্শ](#useful-tips) | ||
56 | + - [গেট ভিউ](#getview) | ||
57 | + - [গেট রেস্পন্সিভ ভিউ](#getresponsiveview) | ||
58 | + - [কিভাবে এটি ব্যবহার করতে হয়](#how-to-use-it) | ||
59 | + - [গেট উইজেট](#getwidget) | ||
60 | + - [গেট এক্স সার্ভিস](#getxservice) | ||
61 | +- [2.0 থেকে পরিবর্তন](#breaking-changes-from-20) | ||
62 | + | ||
63 | +# Get সম্পর্কে | ||
64 | + | ||
65 | +- GetX হল ফ্লটারের জন্য একটি লাইটওয়েট এবং শক্তিশালী সমাধান। এটি দ্রুত এবং ব্যবহারিকভাবে উচ্চ-পারফরম্যান্স স্টেট ব্যবস্থাপনা, বুদ্ধিমান ডিপেনডেন্সি ইনজেকশন এবং রুট ব্যবস্থাপনাকে একত্রিত করে। | ||
66 | + | ||
67 | +- GetX এর ৩টি মৌলিক নীতি রয়েছে: **উৎপাদনশীলতা, কর্মক্ষমতা এবং সংগঠন**। এর মানে হল যে এইগুলি লাইব্রেরির সমস্ত রিসোর্স এর জন্য অগ্রাধিকার। | ||
68 | + | ||
69 | + - **কর্মক্ষমতা:** GetX কর্মক্ষমতা এবং রিসোর্স এর ন্যূনতম ব্যবহারের উপর ফোকাস করে। এটি স্ট্রিম বা চেঞ্জনোটিফায়ার ব্যবহার করে না। | ||
70 | + | ||
71 | + - **উৎপাদনশীলতা:** GetX একটি সহজ এবং মনোরম সিনট্যাক্স ব্যবহার করে। আপনি যা করতে চান না কেন, Getx এর সাথে সর্বদা একটি সহজ উপায় রয়েছে। এটি ডেভেলপমেন্ট এর সময় সাশ্রয় করবে এবং এটি আপনার অ্যাপ্লিকেশনটি সরবরাহ করতে পারে এমন সর্বাধিক কর্মক্ষমতা সরবরাহ করবে। | ||
72 | + | ||
73 | + - **সংগঠন:** GetX ভিউ, প্রেজেন্টেশন লজিক, বিজনেস লজিক, ডিপেন্ডেন্সি ইনজেকশন এবং নেভিগেশনের মোট ডিকপলিং করার অনুমতি দেয়। রুটগুলির মধ্যে নেভিগেট করার জন্য আপনার কনটেক্সট (context) প্রয়োজন নেই, তাই আপনাকে এর জন্য উইজেট ট্রি (ভিজ্যুয়ালাইজেশন) এর উপর নির্ভরশীল হতে হবে না। | ||
74 | + | ||
75 | +- GetX এর একটি বিশাল ইকো সিস্টেম, একটি বৃহত সম্প্রদায়, প্রচুর সংখ্যক সহযোগী রয়েছে এবং যতক্ষণ ফ্লাটার বিদ্যমান থাকবে ততক্ষণ রক্ষণাবেক্ষণ করা হবে। গেটএক্স অ্যান্ড্রয়েড, আইওএস, ওয়েব, ম্যাক, লিনাক্স, উইন্ডোজ এবং আপনার সার্ভারে একই কোড দিয়ে চলতে সক্ষম। **[গেট সার্ভার (Get Server)](https://github.com/jonataslaw/get_server) দিয়ে আপনার ফ্রন্টএন্ডে তৈরি কোডটি পুনরায় সম্পূর্ণরূপে ব্যাকএন্ডে ব্যবহার করা সম্ভব।** | ||
76 | + | ||
77 | +**এছাড়াও সম্পূর্ণ ডেভেলপমেন্ট প্রক্রিয়া সার্ভারে এবং ফ্রন্টএন্ডে [Get CLI](https://github.com/jonataslaw/get_cli) এর মাধ্যমে স্বয়ংক্রিয়ভাবে করা যেতে পারে**। | ||
78 | + | ||
79 | +**এছাড়াও আপনার উত্পাদনশীলতা আরও বাড়াতে, আমাদের রয়েছে [VSCode extension](https://marketplace.visualstudio.com/items?itemName=get-snippets.get-snippets) এবং [Android Studio/Intellij extension](https://plugins.jetbrains.com/plugin/14975-getx-snippets)**। | ||
80 | + | ||
81 | +# ইনস্টল | ||
82 | + | ||
83 | +আপনার pubspec.yaml ফাইলে get যোগ করুন: | ||
84 | + | ||
85 | +```yaml | ||
86 | +dependencies: | ||
87 | + get: | ||
88 | +``` | ||
89 | + | ||
90 | +যে ফাইল এ ব্যবহার করবেন সেখানে ইম্পোর্ট করুন: | ||
91 | + | ||
92 | +```dart | ||
93 | +import 'package:get/get.dart'; | ||
94 | +``` | ||
95 | + | ||
96 | +# GetX দিয়ে কাউন্টার অ্যাপ | ||
97 | + | ||
98 | +Flutter-এ নতুন ডিফল্ট তৈরি করা "কাউন্টার" প্রজেক্টে 100 টিরও বেশি লাইন রয়েছে (মন্তব্য সহ)। Get ব্যবহার করে এটি মাত্র ২৬ লাইনে করা সম্ভব (মন্তব্য সহ)। | ||
99 | + | ||
100 | +- ধাপ 1: | ||
101 | + আপনার MaterialApp এর আগে "Get" যোগ করুন, এটিকে GetMaterialApp এ পরিণত করুন | ||
102 | + | ||
103 | +```dart | ||
104 | +void main() => runApp(GetMaterialApp(home: Home())); | ||
105 | +``` | ||
106 | + | ||
107 | +- নোট: এটি ফ্লটারের MaterialApp পরিবর্তন করে না, GetMaterialApp একটি পরিবর্তিত MaterialApp নয়, এটি শুধুমাত্র একটি পূর্ব-কনফিগার করা উইজেট, যেটিতে একটি চাইল্ড হিসাবে ডিফল্ট MaterialApp আছে। আপনি এটি ম্যানুয়ালি কনফিগার করতে পারেন, তবে এটি অবশ্যই প্রয়োজনীয় নয়। GetMaterialApp রুট তৈরি করবে, সেগুলিকে ইনজেকশন দেবে, অনুবাদগুলি ইনজেকশন করবে, রুট নেভিগেশনের জন্য আপনার প্রয়োজনীয় সমস্ত কিছু ইনজেক্ট করবে। আপনি যদি শুধুমাত্র স্টেট ব্যবস্থাপনা বা ডিপেন্ডেন্সি ব্যবস্থাপনার জন্য Get ব্যবহার করেন, তাহলে GetMaterialApp ব্যবহার করার প্রয়োজন নেই। GetMaterialApp রুট, স্ন্যাকবার, আন্তর্জাতিকীকরণ, বটমশিট, ডায়ালগ এবং রুট সম্পর্কিত উচ্চ-স্তরের এপিএস এবং প্রসঙ্গ অনুপস্থিতির জন্য প্রয়োজনীয়। | ||
108 | +- নোট-²: আপনি যদি রুট ম্যানেজমেন্ট ব্যবহার করেন তবেই এই ধাপটি প্রয়োজনীয় (`Get.to()`, `Get.back()` এবং অন্যান্য)। আপনি যদি এটি ব্যবহার না করেন তবে ধাপ-1 করার দরকার নেই | ||
109 | + | ||
110 | +- ধাপ 2: | ||
111 | + আপনার বিজনেস লজিক ক্লাস তৈরি করুন এবং এর ভিতরে সমস্ত ভেরিয়েবল, পদ্ধতি এবং কন্ট্রোলার রাখুন। | ||
112 | + আপনি একটি সাধারণ ".obs" ব্যবহার করে যেকোনো পরিবর্তনশীলকে পর্যবেক্ষণযোগ্য করতে পারেন। | ||
113 | + | ||
114 | +```dart | ||
115 | +class Controller extends GetxController{ | ||
116 | + var count = 0.obs; | ||
117 | + increment() => count++; | ||
118 | +} | ||
119 | +``` | ||
120 | + | ||
121 | +- ধাপ 3: | ||
122 | + আপনার ভিউ তৈরি করুন, স্টেটলেস উইজেট ব্যবহার করুন এবং কিছু র্যাম সেভ করুন, Get এর সাথে আপনাকে হয়তো আর StatefulWidget ব্যবহার করার প্রয়োজন হবে না। | ||
123 | + | ||
124 | +```dart | ||
125 | +class Home extends StatelessWidget { | ||
126 | + | ||
127 | + @override | ||
128 | + Widget build(context) { | ||
129 | + | ||
130 | + // Instantiate your class using Get.put() to make it available for all "child" routes there. | ||
131 | + final Controller c = Get.put(Controller()); | ||
132 | + | ||
133 | + return Scaffold( | ||
134 | + // Use Obx(()=> to update Text() whenever count is changed. | ||
135 | + appBar: AppBar(title: Obx(() => Text("Clicks: ${c.count}"))), | ||
136 | + | ||
137 | + // Replace the 8 lines Navigator.push by a simple Get.to(). You don't need context | ||
138 | + body: Center(child: ElevatedButton( | ||
139 | + child: Text("Go to Other"), onPressed: () => Get.to(Other()))), | ||
140 | + floatingActionButton: | ||
141 | + FloatingActionButton(child: Icon(Icons.add), onPressed: c.increment)); | ||
142 | + } | ||
143 | +} | ||
144 | + | ||
145 | +class Other extends StatelessWidget { | ||
146 | + // You can ask Get to find a Controller that is being used by another page and redirect you to it. | ||
147 | + final Controller c = Get.find(); | ||
148 | + | ||
149 | + @override | ||
150 | + Widget build(context){ | ||
151 | + // Access the updated count variable | ||
152 | + return Scaffold(body: Center(child: Text("${c.count}"))); | ||
153 | + } | ||
154 | +} | ||
155 | +``` | ||
156 | + | ||
157 | +# GetX এর তিনটি স্তম্ভ | ||
158 | + | ||
159 | +## স্টেট ব্যবস্থাপনা | ||
160 | + | ||
161 | +Get দুই ভিন্ন স্টেট ম্যানেজার আছে: সাধারণ স্টেট ম্যানেজার (আমরা একে GetBuilder বলব) and প্রতিক্রিয়াশীল স্টেট ম্যানেজার (GetX/Obx) | ||
162 | + | ||
163 | +### প্রতিক্রিয়াশীল স্টেট ম্যানেজার | ||
164 | + | ||
165 | +প্রতিক্রিয়াশীল প্রোগ্রামিং অনেক লোককে উদাসীন করতে পারে কারণ এটি জটিল। GetX প্রতিক্রিয়াশীল প্রোগ্রামিংকে বেশ সহজে পরিণত করে: | ||
166 | + | ||
167 | +- আপনাকে StreamControllers তৈরি করতে হবে না। | ||
168 | +- আপনাকে প্রতিটি ভেরিয়েবলের জন্য একটি StreamBuilder তৈরি করতে হবে না। | ||
169 | +- আপনাকে প্রতিটি স্টেটের জন্য একটি ক্লাস তৈরি করতে হবে না। | ||
170 | +- আপনাকে initial value এর জন্য get তৈরি করতে হবে না। | ||
171 | +- আপনাকে কোড জেনারেটর ব্যবহার করতে হবে না। | ||
172 | + | ||
173 | +Get এর সাথে প্রতিক্রিয়াশীল প্রোগ্রামিং setState ব্যবহার করার মতোই সহজ। | ||
174 | + | ||
175 | +কল্পনা করুন যে আপনার একটি নাম ভ্যারিয়েবল আছে এবং আপনি চান যে প্রতিবার আপনি এটি পরিবর্তন করবেন, এটি ব্যবহার করে এমন সমস্ত উইজেট স্বয়ংক্রিয়ভাবে পরিবর্তন করতে পারবেন। | ||
176 | + | ||
177 | +মনে করুন এটি আপনার নাম ভ্যারিয়েবল: | ||
178 | + | ||
179 | +```dart | ||
180 | +var name = 'Ashiqur Rahman Alif'; | ||
181 | +``` | ||
182 | + | ||
183 | +এটিকে observable করতে, আপনাকে এটির শেষে ".obs" যোগ করতে হবে: | ||
184 | + | ||
185 | +```dart | ||
186 | +var name = 'Ashiqur Rahman Alif'.obs; | ||
187 | +``` | ||
188 | + | ||
189 | +এবং UI-তে যখন আপনি সেই নামটি দেখাতে চান এবং যখনই মান পরিবর্তন হয় তখন স্ক্রীনটি আপডেট করতে চান, কেবল এটি করুন: | ||
190 | + | ||
191 | +```dart | ||
192 | +Obx(() => Text("${controller.name}")); | ||
193 | +``` | ||
194 | + | ||
195 | +এখানেই শেষ। এটা এমনই সহজ। | ||
196 | + | ||
197 | +### স্টেট ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত | ||
198 | + | ||
199 | +**স্টেট পরিচালনার আরও ব্যাখ্যা দেখুন [এখানে](./documentation/en_US/state_management.md)। সেখানে আপনি আরও উদাহরণ দেখতে পাবেন এবং সাধারণ স্টেট ব্যবস্থাপক এবং প্রতিক্রিয়াশীল স্টেট ব্যবস্থাপকের মধ্যে পার্থক্যও দেখতে পাবেন** | ||
200 | + | ||
201 | +GetX পাওয়ার সম্পর্কে ভালো ধারণা পাবেন। | ||
202 | + | ||
203 | +## রুট ব্যবস্থাপনা | ||
204 | + | ||
205 | +আপনি যদি context ছাড়াই রুট/স্ন্যাকবার/ডায়ালগ/বটমশীট ব্যবহার করতে চান, GetX আপনার জন্য, এটি দেখুন: | ||
206 | + | ||
207 | +আপনার MaterialApp এর আগে "Get" যোগ করুন, এটিকে GetMaterialApp এ পরিণত করুন | ||
208 | + | ||
209 | +```dart | ||
210 | +GetMaterialApp( // Before: MaterialApp( | ||
211 | + home: MyHome(), | ||
212 | +) | ||
213 | +``` | ||
214 | + | ||
215 | +একটি নতুন স্ক্রিনে নেভিগেট করুন: | ||
216 | + | ||
217 | +```dart | ||
218 | + | ||
219 | +Get.to(NextScreen()); | ||
220 | +``` | ||
221 | + | ||
222 | +নাম সহ নতুন স্ক্রিনে নেভিগেট করুন। নামযুক্ত রুট সম্পর্কিত আরও বিস্তারিত বিবরণ দেখুন [এখানে](./documentation/en_US/route_management.md#navigation-with-named-routes) | ||
223 | + | ||
224 | +```dart | ||
225 | + | ||
226 | +Get.toNamed('/details'); | ||
227 | +``` | ||
228 | + | ||
229 | +স্ন্যাকবার, ডায়ালগ, বটমশীট, বা যেকোনো কিছু বন্ধ করতে আপনি Navigator.pop(context) এর পরিবর্তে ব্যবহার করুন: | ||
230 | + | ||
231 | +```dart | ||
232 | +Get.back(); | ||
233 | +``` | ||
234 | + | ||
235 | +পরবর্তী স্ক্রিনে যাওয়ার পর আগের স্ক্রিনে ফিরে যাওয়া বন্ধ করুন (স্প্ল্যাশস্ক্রিন, লগইন স্ক্রিন ইত্যাদিতে ব্যবহারের জন্য) | ||
236 | + | ||
237 | +```dart | ||
238 | +Get.off(NextScreen()); | ||
239 | +``` | ||
240 | + | ||
241 | +পরবর্তী স্ক্রিনে যেতে এবং আগের সমস্ত রুট বাতিল করতে (শপিং কার্ট, পোল ইত্যাদিতে ব্যবহারের জন্য) | ||
242 | + | ||
243 | +```dart | ||
244 | +Get.offAll(NextScreen()); | ||
245 | +``` | ||
246 | + | ||
247 | +লক্ষ্য করেছেন যে এই জিনিসগুলির কোনটি করার জন্য আপনাকে context ব্যবহার করতে হবে না? এটি Get রুট ম্যানেজমেন্ট ব্যবহার করার সবচেয়ে বড় সুবিধাগুলির মধ্যে একটি। এটির সাহায্যে, আপনি চিন্তা ছাড়াই আপনার controller class এর মধ্যে থেকে এই সমস্ত পদ্ধতিগুলি চালাতে পারেন। | ||
248 | + | ||
249 | +### রুট ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত | ||
250 | + | ||
251 | +**রুট ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত ডকুমেন্টেশন আছে [এখানে](./documentation/en_US/route_management.md)** | ||
252 | + | ||
253 | +## ডিপেনডেন্সি ব্যবস্থাপনা | ||
254 | + | ||
255 | +Get এর একটি সহজ এবং শক্তিশালী ডিপেনডেন্সি পরিচালক রয়েছে যা আপনাকে কোনও Provider context বা inheritedWidget ছাড়াই, মাত্র 1 লাইনের কোডের মাধ্যমে আপনার ব্লক বা কন্ট্রোলারের মতো একই class রিট্রিভ করতে দেয়: | ||
256 | + | ||
257 | +```dart | ||
258 | +Controller controller = Get.put(Controller()); // Rather Controller controller = Controller(); | ||
259 | +``` | ||
260 | + | ||
261 | +- দ্রষ্টব্য: আপনি যদি Get's State Manager ব্যবহার করেন, তাহলে bindings API-এ আরও মনোযোগ দিন, যা আপনার কন্ট্রোলারের সাথে আপনার ভিউকে সংযোগ করা সহজ করে তুলবে। | ||
262 | + | ||
263 | +আপনি যে ক্লাসটি ব্যবহার করছেন তার মধ্যে আপনার ক্লাসকে ইনস্ট্যান্টিয়েট করার পরিবর্তে Get ইনস্ট্যান্সের মধ্যে ইনস্ট্যান্টিয়েট করুন, যা এটিকে আপনার অ্যাপ জুড়ে উপলব্ধ করবে। | ||
264 | +তখন আপনি স্বাভাবিকভাবে আপনার controller (বা class Bloc) ব্যবহার করতে পারবেন। | ||
265 | + | ||
266 | +**টিপ:** Get ডিপেন্ডেন্সি ম্যানেজমেন্ট প্যাকেজের অন্যান্য অংশ থেকে ডিকপল করা হয়েছে, উদাহরণ স্বরূপ, আপনার অ্যাপ ইতিমধ্যেই একটি স্টেট ম্যানেজার ব্যবহার করে (যেকোনোটি হতে পারে, এটা কোন ব্যাপার না), তবে আপনার পুনরায় সব লেখার দরকার নেই, আপনি কোনও সমস্যা ছাড়াই এই ডিপেন্ডেন্সি ইনজেকশনটি ব্যবহার করতে পারেন। | ||
267 | + | ||
268 | +```dart | ||
269 | +controller.fetchApi(); | ||
270 | +``` | ||
271 | + | ||
272 | +কল্পনা করুন যে আপনি অসংখ্য রুটে নেভিগেট করেছেন, এবং আপনার controller এর পিছনে ফেলে আসা ডেটার প্রয়োজন, আপনার প্রোভাইডার বা Get_it এর সাথে মিলিত একটি স্টেট ম্যানেজারের প্রয়োজন হবে, তাই না? Get এর সাথে তা প্রয়োজন নেই। আপনাকে শুধু আপনার controller এর জন্য "find" জিজ্ঞাসা করতে হবে, আপনার কোনো অতিরিক্ত ডিপেন্ডেন্সি প্রয়োজন নেই: | ||
273 | + | ||
274 | +```dart | ||
275 | +Controller controller = Get.find(); | ||
276 | +//Yes, it looks like Magic, Get will find your controller, and will deliver it to you. You can have 1 million controllers instantiated, Get will always give you the right controller. | ||
277 | +``` | ||
278 | + | ||
279 | +এবং তারপরে আপনি আপনার নিয়ামক ডেটা পুনরুদ্ধার করতে সক্ষম হবেন যা সেখানে ফিরে প্রাপ্ত হয়েছিল: | ||
280 | + | ||
281 | +```dart | ||
282 | +Text(controller.textFromApi); | ||
283 | +``` | ||
284 | + | ||
285 | +### ডিপেনডেন্সি ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত | ||
286 | + | ||
287 | +**ডিপেনডেন্সি ব্যবস্থাপনা সম্পর্কে আরো বিস্তারিত ব্যাখ্যা দেখুন [এখানে](./documentation/en_US/dependency_management.md)** | ||
288 | + | ||
289 | +# ইউটিলিটি | ||
290 | + | ||
291 | +## আন্তর্জাতিকীকরণ | ||
292 | + | ||
293 | +### অনুবাদ | ||
294 | + | ||
295 | +অনুবাদগুলি একটি সাধারণ কী-মানের অভিধান মানচিত্র হিসাবে রাখা হয়। | ||
296 | +To add custom translations, create a class and extend `Translations`. | ||
297 | +কাস্টম অনুবাদ যোগ করতে, একটি class তৈরি করুন এবং `Translations` এ extends করুন। | ||
298 | + | ||
299 | +```dart | ||
300 | +import 'package:get/get.dart'; | ||
301 | + | ||
302 | +class Messages extends Translations { | ||
303 | + @override | ||
304 | + Map<String, Map<String, String>> get keys => { | ||
305 | + 'en_US': { | ||
306 | + 'hello': 'Hello World', | ||
307 | + }, | ||
308 | + 'de_DE': { | ||
309 | + 'hello': 'Hallo Welt', | ||
310 | + } | ||
311 | + }; | ||
312 | +} | ||
313 | +``` | ||
314 | + | ||
315 | +#### অনুবাদের ব্যবহার | ||
316 | + | ||
317 | +শুধুমাত্র নির্দিষ্ট key তে `.tr` যোগ করুন এবং এটি অনুবাদ করা হবে, `Get.locale` এবং `Get.fallbackLocale` এর বর্তমান মান ব্যবহার করে। | ||
318 | + | ||
319 | +```dart | ||
320 | +Text('title'.tr); | ||
321 | +``` | ||
322 | + | ||
323 | +#### একবচন এবং বহুবচন সহ অনুবাদ ব্যবহার | ||
324 | + | ||
325 | +```dart | ||
326 | +var products = []; | ||
327 | +Text('singularKey'.trPlural('pluralKey', products.length, Args)); | ||
328 | +``` | ||
329 | + | ||
330 | +#### প্যারামিটার সহ অনুবাদ ব্যবহার | ||
331 | + | ||
332 | +```dart | ||
333 | +import 'package:get/get.dart'; | ||
334 | + | ||
335 | + | ||
336 | +Map<String, Map<String, String>> get keys => { | ||
337 | + 'en_US': { | ||
338 | + 'logged_in': 'logged in as @name with email @email', | ||
339 | + }, | ||
340 | + 'es_ES': { | ||
341 | + 'logged_in': 'iniciado sesión como @name con e-mail @email', | ||
342 | + } | ||
343 | +}; | ||
344 | + | ||
345 | +Text('logged_in'.trParams({ | ||
346 | + 'name': 'Jhon', | ||
347 | + 'email': 'jhon@example.com' | ||
348 | + })); | ||
349 | +``` | ||
350 | + | ||
351 | +### লোকেল | ||
352 | + | ||
353 | +লোকেল এবং অনুবাদ সংজ্ঞায়িত করতে `GetMaterialApp`-এ প্যারামিটার পাস করুন। | ||
354 | + | ||
355 | +```dart | ||
356 | +return GetMaterialApp( | ||
357 | + translations: Messages(), // your translations | ||
358 | + locale: Locale('en', 'US'), // translations will be displayed in that locale | ||
359 | + fallbackLocale: Locale('en', 'UK'), // specify the fallback locale in case an invalid locale is selected. | ||
360 | +); | ||
361 | +``` | ||
362 | + | ||
363 | +#### লোকেল পরিবর্তন করুন | ||
364 | + | ||
365 | +লোকেল আপডেট করতে `Get.updateLocale(locale)` কল করুন। অনুবাদগুলি তখন স্বয়ংক্রিয়ভাবে নতুন লোকেল ব্যবহার করে। | ||
366 | + | ||
367 | +```dart | ||
368 | +var locale = Locale('en', 'US'); | ||
369 | +Get.updateLocale(locale); | ||
370 | +``` | ||
371 | + | ||
372 | +#### লোকেল পদ্ধতি | ||
373 | + | ||
374 | +সিস্টেম লোকেল পড়তে, আপনি `Get.deviceLocale` ব্যবহার করতে পারেন। | ||
375 | + | ||
376 | +```dart | ||
377 | +return GetMaterialApp( | ||
378 | + locale: Get.deviceLocale, | ||
379 | +); | ||
380 | +``` | ||
381 | + | ||
382 | +## থিম পরিবর্তন করুন | ||
383 | + | ||
384 | +Please do not use any higher level widget than `GetMaterialApp` in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with **GetX™**. | ||
385 | + | ||
386 | +You can create your custom theme and simply add it within `Get.changeTheme` without any boilerplate for that: | ||
387 | + | ||
388 | +```dart | ||
389 | +Get.changeTheme(ThemeData.light()); | ||
390 | +``` | ||
391 | + | ||
392 | +If you want to create something like a button that changes the Theme in `onTap`, you can combine two **GetX™** APIs for that: | ||
393 | + | ||
394 | +- The api that checks if the dark `Theme` is being used. | ||
395 | +- And the `Theme` Change API, you can just put this within an `onPressed`: | ||
396 | + | ||
397 | +```dart | ||
398 | +Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark()); | ||
399 | +``` | ||
400 | + | ||
401 | +When `.darkmode` is activated, it will switch to the _light theme_, and when the _light theme_ becomes active, it will change to _dark theme_. | ||
402 | + | ||
403 | +## গেট কানেক্ট (GetConnect) | ||
404 | + | ||
405 | +GetConnect is an easy way to communicate from your back to your front with http or websockets | ||
406 | + | ||
407 | +### ডিফল্ট কনফিগারেশন | ||
408 | + | ||
409 | +You can simply extend GetConnect and use the GET/POST/PUT/DELETE/SOCKET methods to communicate with your Rest API or websockets. | ||
410 | + | ||
411 | +```dart | ||
412 | +class UserProvider extends GetConnect { | ||
413 | + // Get request | ||
414 | + Future<Response> getUser(int id) => get('http://youapi/users/$id'); | ||
415 | + // Post request | ||
416 | + Future<Response> postUser(Map data) => post('http://youapi/users', body: data); | ||
417 | + // Post request with File | ||
418 | + Future<Response<CasesModel>> postCases(List<int> image) { | ||
419 | + final form = FormData({ | ||
420 | + 'file': MultipartFile(image, filename: 'avatar.png'), | ||
421 | + 'otherFile': MultipartFile(image, filename: 'cover.png'), | ||
422 | + }); | ||
423 | + return post('http://youapi/users/upload', form); | ||
424 | + } | ||
425 | + | ||
426 | + GetSocket userMessages() { | ||
427 | + return socket('https://yourapi/users/socket'); | ||
428 | + } | ||
429 | +} | ||
430 | +``` | ||
431 | + | ||
432 | +### কাস্টম কনফিগারেশন | ||
433 | + | ||
434 | +GetConnect is highly customizable You can define base Url, as answer modifiers, as Requests modifiers, define an authenticator, and even the number of attempts in which it will try to authenticate itself, in addition to giving the possibility to define a standard decoder that will transform all your requests into your Models without any additional configuration. | ||
435 | + | ||
436 | +```dart | ||
437 | +class HomeProvider extends GetConnect { | ||
438 | + @override | ||
439 | + void onInit() { | ||
440 | + // All request will pass to jsonEncode so CasesModel.fromJson() | ||
441 | + httpClient.defaultDecoder = CasesModel.fromJson; | ||
442 | + httpClient.baseUrl = 'https://api.covid19api.com'; | ||
443 | + // baseUrl = 'https://api.covid19api.com'; // It define baseUrl to | ||
444 | + // Http and websockets if used with no [httpClient] instance | ||
445 | + | ||
446 | + // It's will attach 'apikey' property on header from all requests | ||
447 | + httpClient.addRequestModifier((request) { | ||
448 | + request.headers['apikey'] = '12345678'; | ||
449 | + return request; | ||
450 | + }); | ||
451 | + | ||
452 | + // Even if the server sends data from the country "Brazil", | ||
453 | + // it will never be displayed to users, because you remove | ||
454 | + // that data from the response, even before the response is delivered | ||
455 | + httpClient.addResponseModifier<CasesModel>((request, response) { | ||
456 | + CasesModel model = response.body; | ||
457 | + if (model.countries.contains('Brazil')) { | ||
458 | + model.countries.remove('Brazilll'); | ||
459 | + } | ||
460 | + }); | ||
461 | + | ||
462 | + httpClient.addAuthenticator((request) async { | ||
463 | + final response = await get("http://yourapi/token"); | ||
464 | + final token = response.body['token']; | ||
465 | + // Set the header | ||
466 | + request.headers['Authorization'] = "$token"; | ||
467 | + return request; | ||
468 | + }); | ||
469 | + | ||
470 | + //Autenticator will be called 3 times if HttpStatus is | ||
471 | + //HttpStatus.unauthorized | ||
472 | + httpClient.maxAuthRetries = 3; | ||
473 | + } | ||
474 | + | ||
475 | + @override | ||
476 | + Future<Response<CasesModel>> getCases(String path) => get(path); | ||
477 | +} | ||
478 | +``` | ||
479 | + | ||
480 | +## গেট পেজ মিডিলওয়্যার | ||
481 | + | ||
482 | +The GetPage has now new property that takes a list of GetMiddleWare and run them in the specific order. | ||
483 | + | ||
484 | +**Note**: When GetPage has a Middlewares, all the children of this page will have the same middlewares automatically. | ||
485 | + | ||
486 | +### অগ্রাধিকার (Priority) | ||
487 | + | ||
488 | +The Order of the Middlewares to run can be set by the priority in the GetMiddleware. | ||
489 | + | ||
490 | +```dart | ||
491 | +final middlewares = [ | ||
492 | + GetMiddleware(priority: 2), | ||
493 | + GetMiddleware(priority: 5), | ||
494 | + GetMiddleware(priority: 4), | ||
495 | + GetMiddleware(priority: -8), | ||
496 | +]; | ||
497 | +``` | ||
498 | + | ||
499 | +those middlewares will be run in this order **-8 => 2 => 4 => 5** | ||
500 | + | ||
501 | +### পুনঃনির্দেশ (Redirect) | ||
502 | + | ||
503 | +This function will be called when the page of the called route is being searched for. It takes RouteSettings as a result to redirect to. Or give it null and there will be no redirecting. | ||
504 | + | ||
505 | +```dart | ||
506 | +RouteSettings redirect(String route) { | ||
507 | + final authService = Get.find<AuthService>(); | ||
508 | + return authService.authed.value ? null : RouteSettings(name: '/login') | ||
509 | +} | ||
510 | +``` | ||
511 | + | ||
512 | +### অন-পেজ কলড (onPageCalled) | ||
513 | + | ||
514 | +This function will be called when this Page is called before anything created | ||
515 | +you can use it to change something about the page or give it new page | ||
516 | + | ||
517 | +```dart | ||
518 | +GetPage onPageCalled(GetPage page) { | ||
519 | + final authService = Get.find<AuthService>(); | ||
520 | + return page.copyWith(title: 'Welcome ${authService.UserName}'); | ||
521 | +} | ||
522 | +``` | ||
523 | + | ||
524 | +### অন-বাইন্ডিং স্টার্ট (OnBindingsStart) | ||
525 | + | ||
526 | +This function will be called right before the Bindings are initialize. | ||
527 | +Here you can change Bindings for this page. | ||
528 | + | ||
529 | +```dart | ||
530 | +List<Bindings> onBindingsStart(List<Bindings> bindings) { | ||
531 | + final authService = Get.find<AuthService>(); | ||
532 | + if (authService.isAdmin) { | ||
533 | + bindings.add(AdminBinding()); | ||
534 | + } | ||
535 | + return bindings; | ||
536 | +} | ||
537 | +``` | ||
538 | + | ||
539 | +### অন-পেজ বিল্ড স্টার্ট (OnPageBuildStart) | ||
540 | + | ||
541 | +This function will be called right after the Bindings are initialize. | ||
542 | +Here you can do something after that you created the bindings and before creating the page widget. | ||
543 | + | ||
544 | +```dart | ||
545 | +GetPageBuilder onPageBuildStart(GetPageBuilder page) { | ||
546 | + print('bindings are ready'); | ||
547 | + return page; | ||
548 | +} | ||
549 | +``` | ||
550 | + | ||
551 | +### অন-পেজ বিল্ড (OnPageBuilt) | ||
552 | + | ||
553 | +This function will be called right after the GetPage.page function is called and will give you the result of the function. and take the widget that will be showed. | ||
554 | + | ||
555 | +### অন-পেজ ডিসপোজ (OnPageDispose) | ||
556 | + | ||
557 | +This function will be called right after disposing all the related objects (Controllers, views, ...) of the page. | ||
558 | + | ||
559 | +## অন্যান্য এপিআই সমূহ | ||
560 | + | ||
561 | +```dart | ||
562 | +// give the current args from currentScreen | ||
563 | +Get.arguments | ||
564 | + | ||
565 | +// give name of previous route | ||
566 | +Get.previousRoute | ||
567 | + | ||
568 | +// give the raw route to access for example, rawRoute.isFirst() | ||
569 | +Get.rawRoute | ||
570 | + | ||
571 | +// give access to Routing API from GetObserver | ||
572 | +Get.routing | ||
573 | + | ||
574 | +// check if snackbar is open | ||
575 | +Get.isSnackbarOpen | ||
576 | + | ||
577 | +// check if dialog is open | ||
578 | +Get.isDialogOpen | ||
579 | + | ||
580 | +// check if bottomsheet is open | ||
581 | +Get.isBottomSheetOpen | ||
582 | + | ||
583 | +// remove one route. | ||
584 | +Get.removeRoute() | ||
585 | + | ||
586 | +// back repeatedly until the predicate returns true. | ||
587 | +Get.until() | ||
588 | + | ||
589 | +// go to next route and remove all the previous routes until the predicate returns true. | ||
590 | +Get.offUntil() | ||
591 | + | ||
592 | +// go to next named route and remove all the previous routes until the predicate returns true. | ||
593 | +Get.offNamedUntil() | ||
594 | + | ||
595 | +//Check in what platform the app is running | ||
596 | +GetPlatform.isAndroid | ||
597 | +GetPlatform.isIOS | ||
598 | +GetPlatform.isMacOS | ||
599 | +GetPlatform.isWindows | ||
600 | +GetPlatform.isLinux | ||
601 | +GetPlatform.isFuchsia | ||
602 | + | ||
603 | +//Check the device type | ||
604 | +GetPlatform.isMobile | ||
605 | +GetPlatform.isDesktop | ||
606 | +//All platforms are supported independently in web! | ||
607 | +//You can tell if you are running inside a browser | ||
608 | +//on Windows, iOS, OSX, Android, etc. | ||
609 | +GetPlatform.isWeb | ||
610 | + | ||
611 | + | ||
612 | +// Equivalent to : MediaQuery.of(context).size.height, | ||
613 | +// but immutable. | ||
614 | +Get.height | ||
615 | +Get.width | ||
616 | + | ||
617 | +// Gives the current context of the Navigator. | ||
618 | +Get.context | ||
619 | + | ||
620 | +// Gives the context of the snackbar/dialog/bottomsheet in the foreground, anywhere in your code. | ||
621 | +Get.contextOverlay | ||
622 | + | ||
623 | +// Note: the following methods are extensions on context. Since you | ||
624 | +// have access to context in any place of your UI, you can use it anywhere in the UI code | ||
625 | + | ||
626 | +// If you need a changeable height/width (like Desktop or browser windows that can be scaled) you will need to use context. | ||
627 | +context.width | ||
628 | +context.height | ||
629 | + | ||
630 | +// Gives you the power to define half the screen, a third of it and so on. | ||
631 | +// Useful for responsive applications. | ||
632 | +// param dividedBy (double) optional - default: 1 | ||
633 | +// param reducedBy (double) optional - default: 0 | ||
634 | +context.heightTransformer() | ||
635 | +context.widthTransformer() | ||
636 | + | ||
637 | +/// Similar to MediaQuery.of(context).size | ||
638 | +context.mediaQuerySize() | ||
639 | + | ||
640 | +/// Similar to MediaQuery.of(context).padding | ||
641 | +context.mediaQueryPadding() | ||
642 | + | ||
643 | +/// Similar to MediaQuery.of(context).viewPadding | ||
644 | +context.mediaQueryViewPadding() | ||
645 | + | ||
646 | +/// Similar to MediaQuery.of(context).viewInsets; | ||
647 | +context.mediaQueryViewInsets() | ||
648 | + | ||
649 | +/// Similar to MediaQuery.of(context).orientation; | ||
650 | +context.orientation() | ||
651 | + | ||
652 | +/// Check if device is on landscape mode | ||
653 | +context.isLandscape() | ||
654 | + | ||
655 | +/// Check if device is on portrait mode | ||
656 | +context.isPortrait() | ||
657 | + | ||
658 | +/// Similar to MediaQuery.of(context).devicePixelRatio; | ||
659 | +context.devicePixelRatio() | ||
660 | + | ||
661 | +/// Similar to MediaQuery.of(context).textScaleFactor; | ||
662 | +context.textScaleFactor() | ||
663 | + | ||
664 | +/// Get the shortestSide from screen | ||
665 | +context.mediaQueryShortestSide() | ||
666 | + | ||
667 | +/// True if width be larger than 800 | ||
668 | +context.showNavbar() | ||
669 | + | ||
670 | +/// True if the shortestSide is smaller than 600p | ||
671 | +context.isPhone() | ||
672 | + | ||
673 | +/// True if the shortestSide is largest than 600p | ||
674 | +context.isSmallTablet() | ||
675 | + | ||
676 | +/// True if the shortestSide is largest than 720p | ||
677 | +context.isLargeTablet() | ||
678 | + | ||
679 | +/// True if the current device is Tablet | ||
680 | +context.isTablet() | ||
681 | + | ||
682 | +/// Returns a value<T> according to the screen size | ||
683 | +/// can give value for: | ||
684 | +/// watch: if the shortestSide is smaller than 300 | ||
685 | +/// mobile: if the shortestSide is smaller than 600 | ||
686 | +/// tablet: if the shortestSide is smaller than 1200 | ||
687 | +/// desktop: if width is largest than 1200 | ||
688 | +context.responsiveValue<T>() | ||
689 | +``` | ||
690 | + | ||
691 | +### ঐচ্ছিক গ্লোবাল সেটিংস এবং ম্যানুয়াল কনফিগারেশন | ||
692 | + | ||
693 | +GetMaterialApp configures everything for you, but if you want to configure Get manually. | ||
694 | + | ||
695 | +```dart | ||
696 | +MaterialApp( | ||
697 | + navigatorKey: Get.key, | ||
698 | + navigatorObservers: [GetObserver()], | ||
699 | +); | ||
700 | +``` | ||
701 | + | ||
702 | +You will also be able to use your own Middleware within `GetObserver`, this will not influence anything. | ||
703 | + | ||
704 | +```dart | ||
705 | +MaterialApp( | ||
706 | + navigatorKey: Get.key, | ||
707 | + navigatorObservers: [ | ||
708 | + GetObserver(MiddleWare.observer) // Here | ||
709 | + ], | ||
710 | +); | ||
711 | +``` | ||
712 | + | ||
713 | +You can create _Global Settings_ for `Get`. Just add `Get.config` to your code before pushing any route. | ||
714 | +Or do it directly in your `GetMaterialApp` | ||
715 | + | ||
716 | +```dart | ||
717 | +GetMaterialApp( | ||
718 | + enableLog: true, | ||
719 | + defaultTransition: Transition.fade, | ||
720 | + opaqueRoute: Get.isOpaqueRouteDefault, | ||
721 | + popGesture: Get.isPopGestureEnable, | ||
722 | + transitionDuration: Get.defaultDurationTransition, | ||
723 | + defaultGlobalState: Get.defaultGlobalState, | ||
724 | +); | ||
725 | + | ||
726 | +Get.config( | ||
727 | + enableLog = true, | ||
728 | + defaultPopGesture = true, | ||
729 | + defaultTransition = Transitions.cupertino | ||
730 | +) | ||
731 | +``` | ||
732 | + | ||
733 | +You can optionally redirect all the logging messages from `Get`. | ||
734 | +If you want to use your own, favourite logging package, | ||
735 | +and want to capture the logs there: | ||
736 | + | ||
737 | +```dart | ||
738 | +GetMaterialApp( | ||
739 | + enableLog: true, | ||
740 | + logWriterCallback: localLogWriter, | ||
741 | +); | ||
742 | + | ||
743 | +void localLogWriter(String text, {bool isError = false}) { | ||
744 | + // pass the message to your favourite logging package here | ||
745 | + // please note that even if enableLog: false log messages will be pushed in this callback | ||
746 | + // you get check the flag if you want through GetConfig.isLogEnable | ||
747 | +} | ||
748 | + | ||
749 | +``` | ||
750 | + | ||
751 | +### লোকাল স্টেট উইজেট | ||
752 | + | ||
753 | +These Widgets allows you to manage a single value, and keep the state ephemeral and locally. | ||
754 | +We have flavours for Reactive and Simple. | ||
755 | +For instance, you might use them to toggle obscureText in a `TextField`, maybe create a custom | ||
756 | +Expandable Panel, or maybe modify the current index in `BottomNavigationBar` while changing the content | ||
757 | +of the body in a `Scaffold`. | ||
758 | + | ||
759 | +#### ভ্যালু বিল্ডার (ValueBuilder) | ||
760 | + | ||
761 | +A simplification of `StatefulWidget` that works with a `.setState` callback that takes the updated value. | ||
762 | + | ||
763 | +```dart | ||
764 | +ValueBuilder<bool>( | ||
765 | + initialValue: false, | ||
766 | + builder: (value, updateFn) => Switch( | ||
767 | + value: value, | ||
768 | + onChanged: updateFn, // same signature! you could use ( newValue ) => updateFn( newValue ) | ||
769 | + ), | ||
770 | + // if you need to call something outside the builder method. | ||
771 | + onUpdate: (value) => print("Value updated: $value"), | ||
772 | + onDispose: () => print("Widget unmounted"), | ||
773 | +), | ||
774 | +``` | ||
775 | + | ||
776 | +#### অবএক্সভ্যালু (ObxValue) | ||
777 | + | ||
778 | +Similar to [`ValueBuilder`](#valuebuilder), but this is the Reactive version, you pass a Rx instance (remember the magical .obs?) and | ||
779 | +updates automatically... isn't it awesome? | ||
780 | + | ||
781 | +```dart | ||
782 | +ObxValue((data) => Switch( | ||
783 | + value: data.value, | ||
784 | + onChanged: data, // Rx has a _callable_ function! You could use (flag) => data.value = flag, | ||
785 | + ), | ||
786 | + false.obs, | ||
787 | +), | ||
788 | +``` | ||
789 | + | ||
790 | +## প্রয়োজনীয় পরামর্শ | ||
791 | + | ||
792 | +`.obs`ervables (also known as _Rx_ Types) have a wide variety of internal methods and operators. | ||
793 | + | ||
794 | +> Is very common to _believe_ that a property with `.obs` **IS** the actual value... but make no mistake! | ||
795 | +> We avoid the Type declaration of the variable, because Dart's compiler is smart enough, and the code | ||
796 | +> looks cleaner, but: | ||
797 | + | ||
798 | +```dart | ||
799 | +var message = 'Hello world'.obs; | ||
800 | +print( 'Message "$message" has Type ${message.runtimeType}'); | ||
801 | +``` | ||
802 | + | ||
803 | +Even if `message` _prints_ the actual String value, the Type is **RxString**! | ||
804 | + | ||
805 | +So, you can't do `message.substring( 0, 4 )`. | ||
806 | +You have to access the real `value` inside the _observable_: | ||
807 | +The most "used way" is `.value`, but, did you know that you can also use... | ||
808 | + | ||
809 | +```dart | ||
810 | +final name = 'GetX'.obs; | ||
811 | +// only "updates" the stream, if the value is different from the current one. | ||
812 | +name.value = 'Hey'; | ||
813 | + | ||
814 | +// All Rx properties are "callable" and returns the new value. | ||
815 | +// but this approach does not accepts `null`, the UI will not rebuild. | ||
816 | +name('Hello'); | ||
817 | + | ||
818 | +// is like a getter, prints 'Hello'. | ||
819 | +name() ; | ||
820 | + | ||
821 | +/// numbers: | ||
822 | + | ||
823 | +final count = 0.obs; | ||
824 | + | ||
825 | +// You can use all non mutable operations from num primitives! | ||
826 | +count + 1; | ||
827 | + | ||
828 | +// Watch out! this is only valid if `count` is not final, but var | ||
829 | +count += 1; | ||
830 | + | ||
831 | +// You can also compare against values: | ||
832 | +count > 2; | ||
833 | + | ||
834 | +/// booleans: | ||
835 | + | ||
836 | +final flag = false.obs; | ||
837 | + | ||
838 | +// switches the value between true/false | ||
839 | +flag.toggle(); | ||
840 | + | ||
841 | + | ||
842 | +/// all types: | ||
843 | + | ||
844 | +// Sets the `value` to null. | ||
845 | +flag.nil(); | ||
846 | + | ||
847 | +// All toString(), toJson() operations are passed down to the `value` | ||
848 | +print( count ); // calls `toString()` inside for RxInt | ||
849 | + | ||
850 | +final abc = [0,1,2].obs; | ||
851 | +// Converts the value to a json Array, prints RxList | ||
852 | +// Json is supported by all Rx types! | ||
853 | +print('json: ${jsonEncode(abc)}, type: ${abc.runtimeType}'); | ||
854 | + | ||
855 | +// RxMap, RxList and RxSet are special Rx types, that extends their native types. | ||
856 | +// but you can work with a List as a regular list, although is reactive! | ||
857 | +abc.add(12); // pushes 12 to the list, and UPDATES the stream. | ||
858 | +abc[3]; // like Lists, reads the index 3. | ||
859 | + | ||
860 | + | ||
861 | +// equality works with the Rx and the value, but hashCode is always taken from the value | ||
862 | +final number = 12.obs; | ||
863 | +print( number == 12 ); // prints > true | ||
864 | + | ||
865 | +/// Custom Rx Models: | ||
866 | + | ||
867 | +// toJson(), toString() are deferred to the child, so you can implement override on them, and print() the observable directly. | ||
868 | + | ||
869 | +class User { | ||
870 | + String name, last; | ||
871 | + int age; | ||
872 | + User({this.name, this.last, this.age}); | ||
873 | + | ||
874 | + @override | ||
875 | + String toString() => '$name $last, $age years old'; | ||
876 | +} | ||
877 | + | ||
878 | +final user = User(name: 'John', last: 'Doe', age: 33).obs; | ||
879 | + | ||
880 | +// `user` is "reactive", but the properties inside ARE NOT! | ||
881 | +// So, if we change some variable inside of it... | ||
882 | +user.value.name = 'Roi'; | ||
883 | +// The widget will not rebuild!, | ||
884 | +// `Rx` don't have any clue when you change something inside user. | ||
885 | +// So, for custom classes, we need to manually "notify" the change. | ||
886 | +user.refresh(); | ||
887 | + | ||
888 | +// or we can use the `update()` method! | ||
889 | +user.update((value){ | ||
890 | + value.name='Roi'; | ||
891 | +}); | ||
892 | + | ||
893 | +print( user ); | ||
894 | +``` | ||
895 | +## StateMixin | ||
896 | + | ||
897 | +Another way to handle your `UI` state is use the `StateMixin<T>` . | ||
898 | +To implement it, use the `with` to add the `StateMixin<T>` | ||
899 | +to your controller which allows a T model. | ||
900 | + | ||
901 | +``` dart | ||
902 | +class Controller extends GetController with StateMixin<User>{} | ||
903 | +``` | ||
904 | + | ||
905 | +The `change()` method change the State whenever we want. | ||
906 | +Just pass the data and the status in this way: | ||
907 | + | ||
908 | +```dart | ||
909 | +change(data, status: RxStatus.success()); | ||
910 | +``` | ||
911 | + | ||
912 | +RxStatus allow these status: | ||
913 | + | ||
914 | +``` dart | ||
915 | +RxStatus.loading(); | ||
916 | +RxStatus.success(); | ||
917 | +RxStatus.empty(); | ||
918 | +RxStatus.error('message'); | ||
919 | +``` | ||
920 | + | ||
921 | +To represent it in the UI, use: | ||
922 | + | ||
923 | +```dart | ||
924 | +class OtherClass extends GetView<Controller> { | ||
925 | + @override | ||
926 | + Widget build(BuildContext context) { | ||
927 | + return Scaffold( | ||
928 | + | ||
929 | + body: controller.obx( | ||
930 | + (state)=>Text(state.name), | ||
931 | + | ||
932 | + // here you can put your custom loading indicator, but | ||
933 | + // by default would be Center(child:CircularProgressIndicator()) | ||
934 | + onLoading: CustomLoadingIndicator(), | ||
935 | + onEmpty: Text('No data found'), | ||
936 | + | ||
937 | + // here also you can set your own error widget, but by | ||
938 | + // default will be an Center(child:Text(error)) | ||
939 | + onError: (error)=>Text(error), | ||
940 | + ), | ||
941 | + ); | ||
942 | +} | ||
943 | +``` | ||
944 | + | ||
945 | +#### গেট ভিউ (GetView) | ||
946 | + | ||
947 | +I love this Widget, is so simple, yet, so useful! | ||
948 | + | ||
949 | +Is a `const Stateless` Widget that has a getter `controller` for a registered `Controller`, that's all. | ||
950 | + | ||
951 | +```dart | ||
952 | + class AwesomeController extends GetController { | ||
953 | + final String title = 'My Awesome View'; | ||
954 | + } | ||
955 | + | ||
956 | + // ALWAYS remember to pass the `Type` you used to register your controller! | ||
957 | + class AwesomeView extends GetView<AwesomeController> { | ||
958 | + @override | ||
959 | + Widget build(BuildContext context) { | ||
960 | + return Container( | ||
961 | + padding: EdgeInsets.all(20), | ||
962 | + child: Text(controller.title), // just call `controller.something` | ||
963 | + ); | ||
964 | + } | ||
965 | + } | ||
966 | +``` | ||
967 | + | ||
968 | +#### গেট রেস্পন্সিভ ভিউ (GetResponsiveView) | ||
969 | + | ||
970 | +Extend this widget to build responsive view. | ||
971 | +this widget contains the `screen` property that have all | ||
972 | +information about the screen size and type. | ||
973 | + | ||
974 | +##### কিভাবে এটি ব্যবহার করতে হয় | ||
975 | + | ||
976 | +You have two options to build it. | ||
977 | + | ||
978 | +- with `builder` method you return the widget to build. | ||
979 | +- with methods `desktop`, `tablet`,`phone`, `watch`. the specific | ||
980 | + method will be built when the screen type matches the method | ||
981 | + when the screen is [ScreenType.Tablet] the `tablet` method | ||
982 | + will be exuded and so on. | ||
983 | + **Note:** If you use this method please set the property `alwaysUseBuilder` to `false` | ||
984 | + | ||
985 | +With `settings` property you can set the width limit for the screen types. | ||
986 | + | ||
987 | + | ||
988 | +Code to this screen | ||
989 | +[code](https://github.com/SchabanBo/get_page_example/blob/master/lib/pages/responsive_example/responsive_view.dart) | ||
990 | + | ||
991 | +#### গেট উইজেট (GetWidget) | ||
992 | + | ||
993 | +Most people have no idea about this Widget, or totally confuse the usage of it. | ||
994 | +The use case is very rare, but very specific: It `caches` a Controller. | ||
995 | +Because of the _cache_, can't be a `const Stateless`. | ||
996 | + | ||
997 | +> So, when do you need to "cache" a Controller? | ||
998 | + | ||
999 | +If you use, another "not so common" feature of **GetX**: `Get.create()`. | ||
1000 | + | ||
1001 | +`Get.create(()=>Controller())` will generate a new `Controller` each time you call | ||
1002 | +`Get.find<Controller>()`, | ||
1003 | + | ||
1004 | +That's where `GetWidget` shines... as you can use it, for example, | ||
1005 | +to keep a list of Todo items. So, if the widget gets "rebuilt", it will keep the same controller instance. | ||
1006 | + | ||
1007 | +#### গেট এক্স সার্ভিস (GetxService) | ||
1008 | + | ||
1009 | +This class is like a `GetxController`, it shares the same lifecycle ( `onInit()`, `onReady()`, `onClose()`). | ||
1010 | +But has no "logic" inside of it. It just notifies **GetX** Dependency Injection system, that this subclass | ||
1011 | +**can not** be removed from memory. | ||
1012 | + | ||
1013 | +So is super useful to keep your "Services" always reachable and active with `Get.find()`. Like: | ||
1014 | +`ApiService`, `StorageService`, `CacheService`. | ||
1015 | + | ||
1016 | +```dart | ||
1017 | +Future<void> main() async { | ||
1018 | + await initServices(); /// AWAIT SERVICES INITIALIZATION. | ||
1019 | + runApp(SomeApp()); | ||
1020 | +} | ||
1021 | + | ||
1022 | +/// Is a smart move to make your Services intiialize before you run the Flutter app. | ||
1023 | +/// as you can control the execution flow (maybe you need to load some Theme configuration, | ||
1024 | +/// apiKey, language defined by the User... so load SettingService before running ApiService. | ||
1025 | +/// so GetMaterialApp() doesnt have to rebuild, and takes the values directly. | ||
1026 | +void initServices() async { | ||
1027 | + print('starting services ...'); | ||
1028 | + /// Here is where you put get_storage, hive, shared_pref initialization. | ||
1029 | + /// or moor connection, or whatever that's async. | ||
1030 | + await Get.putAsync(() => DbService().init()); | ||
1031 | + await Get.putAsync(SettingsService()).init(); | ||
1032 | + print('All services started...'); | ||
1033 | +} | ||
1034 | + | ||
1035 | +class DbService extends GetxService { | ||
1036 | + Future<DbService> init() async { | ||
1037 | + print('$runtimeType delays 2 sec'); | ||
1038 | + await 2.delay(); | ||
1039 | + print('$runtimeType ready!'); | ||
1040 | + return this; | ||
1041 | + } | ||
1042 | +} | ||
1043 | + | ||
1044 | +class SettingsService extends GetxService { | ||
1045 | + void init() async { | ||
1046 | + print('$runtimeType delays 1 sec'); | ||
1047 | + await 1.delay(); | ||
1048 | + print('$runtimeType ready!'); | ||
1049 | + } | ||
1050 | +} | ||
1051 | + | ||
1052 | +``` | ||
1053 | + | ||
1054 | +The only way to actually delete a `GetxService`, is with `Get.reset()` which is like a | ||
1055 | +"Hot Reboot" of your app. So remember, if you need absolute persistence of a class instance during the | ||
1056 | +lifetime of your app, use `GetxService`. | ||
1057 | + | ||
1058 | + | ||
1059 | +### পরীক্ষা (Tests) | ||
1060 | + | ||
1061 | +You can test your controllers like any other class, including their lifecycles: | ||
1062 | + | ||
1063 | +```dart | ||
1064 | +class Controller extends GetxController { | ||
1065 | + @override | ||
1066 | + void onInit() { | ||
1067 | + super.onInit(); | ||
1068 | + //Change value to name2 | ||
1069 | + name.value = 'name2'; | ||
1070 | + } | ||
1071 | + | ||
1072 | + @override | ||
1073 | + void onClose() { | ||
1074 | + name.value = ''; | ||
1075 | + super.onClose(); | ||
1076 | + } | ||
1077 | + | ||
1078 | + final name = 'name1'.obs; | ||
1079 | + | ||
1080 | + void changeName() => name.value = 'name3'; | ||
1081 | +} | ||
1082 | + | ||
1083 | +void main() { | ||
1084 | + test(''' | ||
1085 | +Test the state of the reactive variable "name" across all of its lifecycles''', | ||
1086 | + () { | ||
1087 | + /// You can test the controller without the lifecycle, | ||
1088 | + /// but it's not recommended unless you're not using | ||
1089 | + /// GetX dependency injection | ||
1090 | + final controller = Controller(); | ||
1091 | + expect(controller.name.value, 'name1'); | ||
1092 | + | ||
1093 | + /// If you are using it, you can test everything, | ||
1094 | + /// including the state of the application after each lifecycle. | ||
1095 | + Get.put(controller); // onInit was called | ||
1096 | + expect(controller.name.value, 'name2'); | ||
1097 | + | ||
1098 | + /// Test your functions | ||
1099 | + controller.changeName(); | ||
1100 | + expect(controller.name.value, 'name3'); | ||
1101 | + | ||
1102 | + /// onClose was called | ||
1103 | + Get.delete<Controller>(); | ||
1104 | + | ||
1105 | + expect(controller.name.value, ''); | ||
1106 | + }); | ||
1107 | +} | ||
1108 | +``` | ||
1109 | + | ||
1110 | +#### পরামর্শ | ||
1111 | + | ||
1112 | +##### Mockito or mocktail | ||
1113 | +If you need to mock your GetxController/GetxService, you should extend GetxController, and mixin it with Mock, that way | ||
1114 | + | ||
1115 | +```dart | ||
1116 | +class NotificationServiceMock extends GetxService with Mock implements NotificationService {} | ||
1117 | +``` | ||
1118 | + | ||
1119 | +##### Using Get.reset() | ||
1120 | +If you are testing widgets, or test groups, use Get.reset at the end of your test or in tearDown to reset all settings from your previous test. | ||
1121 | + | ||
1122 | +##### Get.testMode | ||
1123 | +if you are using your navigation in your controllers, use `Get.testMode = true` at the beginning of your main. | ||
1124 | + | ||
1125 | + | ||
1126 | +# 2.0 থেকে পরিবর্তন | ||
1127 | + | ||
1128 | +1- Rx এর প্রকারভেদ : | ||
1129 | + | ||
1130 | +| পূর্বে | এখন | | ||
1131 | +| ------- | ---------- | | ||
1132 | +| StringX | `RxString` | | ||
1133 | +| IntX | `RxInt` | | ||
1134 | +| MapX | `RxMap` | | ||
1135 | +| ListX | `RxList` | | ||
1136 | +| NumX | `RxNum` | | ||
1137 | +| DoubleX | `RxDouble` | | ||
1138 | + | ||
1139 | +RxController এবং GetBuilder এখন একত্রিত, আপনি কোন নিয়ামক ব্যবহার করতে চান তা আর মুখস্ত করার দরকার নেই, শুধু GetxController ব্যবহার করুন, এটি সাধারণ স্টেট ব্যবস্থাপনা এবং প্রতিক্রিয়াশীল স্টেট ব্যবস্থাপনা এর জন্যও কাজ করবে। | ||
1140 | + | ||
1141 | +2- নেমড রুটস (NamedRoutes) | ||
1142 | + | ||
1143 | +আগে: | ||
1144 | + | ||
1145 | +```dart | ||
1146 | +GetMaterialApp( | ||
1147 | + namedRoutes: { | ||
1148 | + '/': GetRoute(page: Home()), | ||
1149 | + } | ||
1150 | +) | ||
1151 | +``` | ||
1152 | + | ||
1153 | +এখন: | ||
1154 | + | ||
1155 | +```dart | ||
1156 | +GetMaterialApp( | ||
1157 | + getPages: [ | ||
1158 | + GetPage(name: '/', page: () => Home()), | ||
1159 | + ] | ||
1160 | +) | ||
1161 | +``` | ||
1162 | + | ||
1163 | +কেন এই পরিবর্তন? প্রায়শই, কোন পৃষ্ঠাটি প্যারামিটার বা লগইন টোকেন থেকে প্রদর্শিত হবে তা নির্ধারণ করার প্রয়োজন হতে পারে, পূর্ববর্তী পদ্ধতিটি অনমনীয় ছিল, কারণ এটি সেই অনুমতি দিতো না। | ||
1164 | +এটি ফাংশনে পৃষ্ঠাটি ইনসার্ট করার জন্য উল্লেখযোগ্যভাবে RAM খরচ হ্রাস করেছে, যেহেতু অ্যাপটি শুরু হওয়ার পর থেকে রুটগুলি মেমরিতে বরাদ্দ করা হবে না, এটি এই ধরণের পদ্ধতিরও অনুমতি দেয়: | ||
1165 | + | ||
1166 | +```dart | ||
1167 | + | ||
1168 | +GetStorage box = GetStorage(); | ||
1169 | + | ||
1170 | +GetMaterialApp( | ||
1171 | + getPages: [ | ||
1172 | + GetPage(name: '/', page:(){ | ||
1173 | + return box.hasData('token') ? Home() : Login(); | ||
1174 | + }) | ||
1175 | + ] | ||
1176 | +) | ||
1177 | +``` |
@@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
35 | [](README-fr.md) | 35 | [](README-fr.md) |
36 | [](README.ja-JP.md) | 36 | [](README.ja-JP.md) |
37 | [](README-hi.md) | 37 | [](README-hi.md) |
38 | +[](README-bn.md) | ||
38 | 39 | ||
39 | 40 | ||
40 | </div> | 41 | </div> |
-
Please register or login to post a comment