본문 바로가기
개발/Flutter

Flutter에서 지네릭 메서드 만들기

by dev_caleb 2022. 9. 2.
728x90
Future<T> matjipLike<T>(
    {required MatjipModel matjipModel,
    required UserModel userModel,
    required T model,
    required bool like //true -> like, false unlike
    }) async {

지네릭을 메서드를 이해하고 사용은 해왔지만, 실제로 지네릭 메서드를 만들어서 사용해 본 적은 없었다. 그런데 코딩을 할수록, 함수의 재사용성을 고려해볼 때 지네릭을 사용해서 메서드를 만들면 훨씬 재사용성이 늘 것 같은 생각에, 만들어보기로 했다. 코드가 훨씬 줄어들 것이라고 예상하고 있다

 

https://stackoverflow.com/questions/42004475/how-to-create-a-generic-method-in-dart

 

How to create a generic method in Dart?

I'm trying to use generic methods in Dart (1.22.0-dev.10.3). Here is a simple example: abstract class VR<T> { VR(); bool foo<T>(T value); } class VRInt extends VR<int> { ...

stackoverflow.com

 

728x90