๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ํ”Œ๋Ÿฌํ„ฐ (Flutter)

Provider ์ง์ ‘ ์ƒ์„ฑ ๋ฐ ์ดํ•ด

by ์Šค์นด ๐Ÿ€ 2020. 8. 25.

import 'package:flutter/material.dart';
import 'package:time_tracker_flutter_course/services/auth.dart';

//Provider ์ง์ ‘ ์ƒ์„ฑ
class AuthProvider extends InheritedWidget {
AuthProvider({@required this.auth, @required this.child});
final AuthBase auth;
final Widget child;

@override
bool updateShouldNotify(InheritedWidget oldWidget) => false;

//final auth =AuthProvider.of(context);
// static ์ •์  ์„ ์–ธ ๋ฉ”์„œ๋“œ ?์•„๋ฌด๋ฐ์„œ๋‚˜ ํ˜ธ์ถœ ๊ฐ€๋Šฅ
static AuthBase of(BuildContext context) {
AuthProvider provider =
context.dependOnInheritedWidgetOfExactType<AuthProvider>();
return provider.auth;
}
}