Skip to content

Commit

Permalink
Add main with the new home page 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
sbis04 committed Feb 23, 2021
1 parent 9ca4b1d commit fe5fca6
Showing 1 changed file with 4 additions and 62 deletions.
66 changes: 4 additions & 62 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'screens/home_page.dart';

void main() {
runApp(
ProviderScope(
Expand All @@ -9,76 +11,16 @@ void main() {
);
}

class CounterNotifier extends ChangeNotifier {
int _value = 0;
int get value => _value;

void incrementValue() {
_value++;
notifyListeners();
}
}

final counterProvider = ChangeNotifierProvider((ref) => CounterNotifier());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Counter',
title: 'Flutter Riverpod StateNotifier',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
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> {
void _incrementCounter(BuildContext context) {
context.read(counterProvider).incrementValue();
}

@override
Widget build(BuildContext 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:',
),
Consumer(
builder: (context, watch, child) {
final counterNotifier = watch(counterProvider);
return Text(
'${counterNotifier.value}',
style: Theme.of(context).textTheme.headline4,
);
},
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _incrementCounter(context),
tooltip: 'Increment',
child: Icon(Icons.add),
),
home: HomePage(),
);
}
}

0 comments on commit fe5fca6

Please sign in to comment.