StateProvider Widget: Watch Function

Learn about the StateProvider widget in Riverpod and how the watch function works.

Watching the StateProvider

Although the code snippet is shorter than the other, it still plays an essential role in watching the Provider.

Press + to interact
import 'package:flutter/material.dart';
class WatchNameAndCity extends StatelessWidget {
const WatchNameAndCity({
Key? key,
@required this.stateProviderNameObject,
@required this.stateProviderCityObject,
}) : super(key: key);
final String? stateProviderNameObject;
final String? stateProviderCityObject;
@override
Widget build(BuildContext context) {
return Text(
stateProviderNameObject! + ' from ' + stateProviderCityObject!,
style: TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
);
}
}

This process of breaking down the whole app architecture may seem daunting, but it is necessary. Moreover, it makes our code testable, and produces less boilerplate code.

Now, as regards the less boilerplate, the Riverpod state management makes a huge difference.

Why so? Because now we can place our ...

Get hands-on with 1400+ tech skills courses.