s_provider 1.0.0 copy "s_provider: ^1.0.0" to clipboard
s_provider: ^1.0.0 copied to clipboard

Flutter state management package. The most basic form of provider. It takes a value and exposes it, whatever the value is..

example/main.dart

import 'package:flutter/material.dart';
import 'package:s_provider/s_provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  _MyHomePageState() {
    StaticProvider.addProvider(CountStaticProvider());
  }

  @override
  Widget build(BuildContext context) {
    CountStaticProvider provider =
        StaticProvider.of<CountStaticProvider>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              provider.count.toString(),
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => provider.add(),
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}


class CountStaticProvider extends StaticChangeNotifier {
  int count = 0;

  add() {
    count++;
    notifyListeners();
  }

  remove() {
    count--;
    notifyListeners();
  }
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Flutter state management package. The most basic form of provider. It takes a value and exposes it, whatever the value is..

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on s_provider