Showing
1 changed file
with
165 additions
and
2 deletions
1 |  | 1 |  |
2 | 2 | ||
3 | -_Languages: [영어](README.md), [중국어](README.zh-cn.md), [브라질 포르투칼어](README.pt-br.md), [스페인어](README-es.md), [러시아어](README.ru.md), [폴란드어](README.pl.md), 한국어(이파일)._ | 3 | +**언어: [영어](README.md), [중국어](README.zh-cn.md), [브라질 포르투칼어](README.pt-br.md), [스페인어](README-es.md), [러시아어](README.ru.md), [폴란드어](README.pl.md), 한국어(이파일).** |
4 | 4 | ||
5 | [](https://pub.dev/packages/get) | 5 | [](https://pub.dev/packages/get) |
6 | [](https://pub.dev/packages/get/score) | 6 | [](https://pub.dev/packages/get/score) |
@@ -35,6 +35,17 @@ _Languages: [영어](README.md), [중국어](README.zh-cn.md), [브라질 포르 | @@ -35,6 +35,17 @@ _Languages: [영어](README.md), [중국어](README.zh-cn.md), [브라질 포르 | ||
35 | - [지역 변경](#지역-변경) | 35 | - [지역 변경](#지역-변경) |
36 | - [시스템 지역](#시스템-지역) | 36 | - [시스템 지역](#시스템-지역) |
37 | - [테마 변경](#테마-변경) | 37 | - [테마 변경](#테마-변경) |
38 | + - [GetConnect](#getconnect) | ||
39 | + - [Default configuration](#default-configuration) | ||
40 | + - [Custom configuration](#custom-configuration) | ||
41 | + - [GetPage Middleware](#getpage-middleware) | ||
42 | + - [Priority](#priority) | ||
43 | + - [Redirect](#redirect) | ||
44 | + - [onPageCalled](#onpagecalled) | ||
45 | + - [OnBindingsStart](#onbindingsstart) | ||
46 | + - [OnPageBuildStart](#onpagebuildstart) | ||
47 | + - [OnPageBuilt](#onpagebuilt) | ||
48 | + - [OnPageDispose](#onpagedispose) | ||
38 | - [기타 고급 API](#기타-고급-API) | 49 | - [기타 고급 API](#기타-고급-API) |
39 | - [선택적 전역 설정과 수동 구성](#선택적-전역-설정과-수동-구성) | 50 | - [선택적 전역 설정과 수동 구성](#선택적-전역-설정과-수동-구성) |
40 | - [지역 상태 위젯들](#지역-상태-위젯들) | 51 | - [지역 상태 위젯들](#지역-상태-위젯들) |
@@ -380,6 +391,158 @@ Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark()); | @@ -380,6 +391,158 @@ Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark()); | ||
380 | 391 | ||
381 | `.darkmode`가 활성활 될때 _light theme_ 로 바뀔것 이고 _light theme_ 가 활성화되면 _dark theme_ 로 변경될 것입니다. | 392 | `.darkmode`가 활성활 될때 _light theme_ 로 바뀔것 이고 _light theme_ 가 활성화되면 _dark theme_ 로 변경될 것입니다. |
382 | 393 | ||
394 | +## GetConnect | ||
395 | +GetConnect is an easy way to communicate from your back to your front with http or websockets | ||
396 | + | ||
397 | +### Default configuration | ||
398 | +You can simply extend GetConnect and use the GET/POST/PUT/DELETE/SOCKET methods to communicate with your Rest API or websockets. | ||
399 | + | ||
400 | +```dart | ||
401 | +class UserProvider extends GetConnect { | ||
402 | + // Get request | ||
403 | + Future<Response> getUser(int id) => get('http://youapi/users/$id'); | ||
404 | + // Post request | ||
405 | + Future<Response> postUser(Map data) => post('http://youapi/users', body: data); | ||
406 | + // Post request with File | ||
407 | + Future<Response<CasesModel>> postCases(List<int> image) { | ||
408 | + final form = FormData({ | ||
409 | + 'file': MultipartFile(image, filename: 'avatar.png'), | ||
410 | + 'otherFile': MultipartFile(image, filename: 'cover.png'), | ||
411 | + }); | ||
412 | + return post('http://youapi/users/upload', form); | ||
413 | + } | ||
414 | + | ||
415 | + GetSocket userMessages() { | ||
416 | + return socket('https://yourapi/users/socket'); | ||
417 | + } | ||
418 | +} | ||
419 | +``` | ||
420 | +### Custom configuration | ||
421 | +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. | ||
422 | + | ||
423 | +```dart | ||
424 | +class HomeProvider extends GetConnect { | ||
425 | + @override | ||
426 | + void onInit() { | ||
427 | + // All request will pass to jsonEncode so CasesModel.fromJson() | ||
428 | + httpClient.defaultDecoder = CasesModel.fromJson; | ||
429 | + httpClient.baseUrl = 'https://api.covid19api.com'; | ||
430 | + // baseUrl = 'https://api.covid19api.com'; // It define baseUrl to | ||
431 | + // Http and websockets if used with no [httpClient] instance | ||
432 | + | ||
433 | + // It's will attach 'apikey' property on header from all requests | ||
434 | + httpClient.addRequestModifier((request) { | ||
435 | + request.headers['apikey'] = '12345678'; | ||
436 | + return request; | ||
437 | + }); | ||
438 | + | ||
439 | + // Even if the server sends data from the country "Brazil", | ||
440 | + // it will never be displayed to users, because you remove | ||
441 | + // that data from the response, even before the response is delivered | ||
442 | + httpClient.addResponseModifier<CasesModel>((request, response) { | ||
443 | + CasesModel model = response.body; | ||
444 | + if (model.countries.contains('Brazil')) { | ||
445 | + model.countries.remove('Brazilll'); | ||
446 | + } | ||
447 | + }); | ||
448 | + | ||
449 | + httpClient.addAuthenticator((request) async { | ||
450 | + final response = await get("http://yourapi/token"); | ||
451 | + final token = response.body['token']; | ||
452 | + // Set the header | ||
453 | + request.headers['Authorization'] = "$token"; | ||
454 | + return request; | ||
455 | + }); | ||
456 | + | ||
457 | + //Autenticator will be called 3 times if HttpStatus is | ||
458 | + //HttpStatus.unauthorized | ||
459 | + httpClient.maxAuthRetries = 3; | ||
460 | + } | ||
461 | + } | ||
462 | + | ||
463 | + @override | ||
464 | + Future<Response<CasesModel>> getCases(String path) => get(path); | ||
465 | +} | ||
466 | +``` | ||
467 | + | ||
468 | +## GetPage Middleware | ||
469 | + | ||
470 | +The GetPage has now new property that takes a list of GetMiddleWare and run them in the specific order. | ||
471 | + | ||
472 | +**Note**: When GetPage has a Middlewares, all the children of this page will have the same middlewares automatically. | ||
473 | + | ||
474 | +### Priority | ||
475 | + | ||
476 | +The Order of the Middlewares to run can pe set by the priority in the GetMiddleware. | ||
477 | + | ||
478 | +```dart | ||
479 | +final middlewares = [ | ||
480 | + GetMiddleware(priority: 2), | ||
481 | + GetMiddleware(priority: 5), | ||
482 | + GetMiddleware(priority: 4), | ||
483 | + GetMiddleware(priority: -8), | ||
484 | +]; | ||
485 | +``` | ||
486 | +those middlewares will be run in this order **-8 => 2 => 4 => 5** | ||
487 | + | ||
488 | +### Redirect | ||
489 | + | ||
490 | +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. | ||
491 | + | ||
492 | +```dart | ||
493 | +GetPage redirect( ) { | ||
494 | + final authService = Get.find<AuthService>(); | ||
495 | + return authService.authed.value ? null : RouteSettings(name: '/login') | ||
496 | +} | ||
497 | +``` | ||
498 | + | ||
499 | +### onPageCalled | ||
500 | + | ||
501 | +This function will be called when this Page is called before anything created | ||
502 | +you can use it to change something about the page or give it new page | ||
503 | + | ||
504 | +```dart | ||
505 | +GetPage onPageCalled(GetPage page) { | ||
506 | + final authService = Get.find<AuthService>(); | ||
507 | + return page.copyWith(title: 'Welcome ${authService.UserName}'); | ||
508 | +} | ||
509 | +``` | ||
510 | + | ||
511 | +### OnBindingsStart | ||
512 | + | ||
513 | +This function will be called right before the Bindings are initialize. | ||
514 | +Here you can change Bindings for this page. | ||
515 | + | ||
516 | +```dart | ||
517 | +List<Bindings> onBindingsStart(List<Bindings> bindings) { | ||
518 | + final authService = Get.find<AuthService>(); | ||
519 | + if (authService.isAdmin) { | ||
520 | + bindings.add(AdminBinding()); | ||
521 | + } | ||
522 | + return bindings; | ||
523 | +} | ||
524 | +``` | ||
525 | + | ||
526 | +### OnPageBuildStart | ||
527 | + | ||
528 | +This function will be called right after the Bindings are initialize. | ||
529 | +Here you can do something after that you created the bindings and before creating the page widget. | ||
530 | + | ||
531 | +```dart | ||
532 | +GetPageBuilder onPageBuildStart(GetPageBuilder page) { | ||
533 | + print('bindings are ready'); | ||
534 | + return page; | ||
535 | +} | ||
536 | +``` | ||
537 | + | ||
538 | +### OnPageBuilt | ||
539 | + | ||
540 | +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. | ||
541 | + | ||
542 | +### OnPageDispose | ||
543 | + | ||
544 | +This function will be called right after disposing all the related objects (Controllers, views, ...) of the page. | ||
545 | + | ||
383 | ## 기타 고급 API | 546 | ## 기타 고급 API |
384 | 547 | ||
385 | ```dart | 548 | ```dart |
@@ -733,7 +896,7 @@ print( user ); | @@ -733,7 +896,7 @@ print( user ); | ||
733 | Widget build(BuildContext context) { | 896 | Widget build(BuildContext context) { |
734 | return Container( | 897 | return Container( |
735 | padding: EdgeInsets.all(20), | 898 | padding: EdgeInsets.all(20), |
736 | - child: Text( controller.title ), // 단지 `controller.something`을 호출합니다. | 899 | + child: Text(controller.title), // 단지 `controller.something`을 호출합니다. |
737 | ); | 900 | ); |
738 | } | 901 | } |
739 | } | 902 | } |
-
Please register or login to post a comment