[flutter] flutter 6 (Riverpod)

허성재's avatar
Oct 11, 2024
[flutter] flutter 6 (Riverpod)
riverpod를 배워보자
옵저버 패턴
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: HomePage(), ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Expanded( child: Center( child: Container( child: Text("1", style: TextStyle(fontSize: 100))))), Expanded( child: Center( child: Container( child: InkWell( onTap: () { print("증가 클릭됨"); }, child: Text("증가", style: TextStyle(fontSize: 100))), ), ), ), ], ), ); } }
간단하게 1과 증가 버튼을 만들었다.
notion image
notion image
notion image
notion image
notion image
notion image
notion image
dart파일은 전부 소문자에 언더바를 사용
notion image
notion image
인제 탑에 사용해보자
notion image
이렇게 한다고만 되는게 아니다.
notion image
스코프를 등록해야된다.
notion image
 
해당 컨슘위젯에서 read될때 창고생성됨
싱글톤으로 관리됨
notion image
provider를 구분지어 만들어주자
notion image
notion image
notifyprovider는 state안의 변수를 직접 바꾸는게 아니라 아예 새로운 model을 new해서 넣어야
notion image
watch는 관리하는 데이터 자체를 가져온다.
Share article

heo-gom