Skip to content

Instantly share code, notes, and snippets.

@AbhishekDoshi26
Created October 5, 2021 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhishekDoshi26/83817a7f775cdcb63118646bfdbf7c8d to your computer and use it in GitHub Desktop.
Save AbhishekDoshi26/83817a7f775cdcb63118646bfdbf7c8d to your computer and use it in GitHub Desktop.
home.dart of statenotifier example
import 'package:flutter/material.dart';
import 'package:flutter_state_notifier/flutter_state_notifier.dart';
import 'package:state_notifier_example/counter_service.dart';
class Home extends StatelessWidget {
Home({Key? key}) : super(key: key);
final CounterService _counterService = CounterService(0);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('StateNotifier Example'),
),
bottomNavigationBar: Container(
color: Colors.red,
height: 50.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () => _counterService.incrementCounter(),
icon: Icon(Icons.add),
splashRadius: 0.1,
),
IconButton(
onPressed: () => _counterService.decrementCounter(),
icon: Icon(Icons.remove),
splashRadius: 0.1,
),
IconButton(
onPressed: () => _counterService.resetCounter(),
icon: Icon(Icons.restart_alt),
splashRadius: 0.1,
),
],
),
),
body: Center(
child: StateNotifierBuilder(
stateNotifier: _counterService,
builder: (BuildContext context, int value, Widget? child) {
return Text(
'$value',
style: TextStyle(fontSize: 50.0),
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment