Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Add a Simple Provider

This video was last updated on Sep 22 2022

Learn how to use the very first Provider aptly called Provider. You’ll learn how to use this to fetch model data as well as some limitations.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

Now that you have an understanding of Provider, it’s time to put it to the test. We’re going to create a widget aptly called Provider. This widget provides two important methods, create and dispose.

provider: ^6.0.3
import 'package:provider/provider.dart';
import 'models/pillar.dart';
body: Provider<Pillar>(
    child: const TutorialsPage()),
create: (context) =>
                Pillar(type: PillarType.flutter, articleCount: 115),
import 'package:provider/provider.dart';
import '../models/pillar.dart';
final pillar = Provider.of<Pillar>(context);
children: <Widget>[
  const Center(
    child: TutorialWidget(),
  ),
  Padding(
    padding: const EdgeInsets.only(top: 24.0),
    child: Text(
      'Total Tutorials: ${pillar.articleCount}',
      style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
    ),
  )
],
import 'package:provider/provider.dart';
import '../models/pillar.dart';
final pillar = Provider.of<Pillar>(context);
return Stack(
  children: [
    InkWell(
      onTap: () {
        pillar.increaseArticleCount();
      },
      child:
          Image.asset('assets/images/${pillar.type.imageName}', width: 110, height: 110),
    ),
    Positioned(
      bottom: 2,
      child: CircleAvatar(
        backgroundColor: Colors.blue,
        child: Text(pillar.articleCount.toString()),
      ),
    )
  ],
);

Reviews

Comments