Slide 68
Slide 68 text
ViewModel Λ࡞ͬͯཧ͢Δʁ
ίϯϙʔωϯτͷ୯ҐΛࡉ͔͘͢Ε
ͦͷ͚ͩରʹͳΔViewModel
૿͑Δʁ
͜ͷϘλϯͷঢ়ଶཧͲ͏͢Δʁ
class ChatViewModel {
String text = '';
bool enabled = false;
}
class ChatWidget extends HookConsumerWidget {
const ChatWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
final viewModel = ref.watch(chatViewModelProvider);
return Column(
children: [
TextFormField(
onChanged: (value) => viewModel.enabled = value.isNotEmpty,
),
ElevatedButton(
onPressed: viewModel.enabled ? () {/** Submit **/} : null,
child: Text('Submit'),
),
],
);
}
}