-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
main.dart
110 lines (99 loc) · 3.02 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'package:flutter/material.dart';
import 'package:dashclicker/logic/dash_purchases.dart';
import 'package:dashclicker/logic/firebase_notifier.dart';
import 'package:dashclicker/repo/iap_repo.dart';
import 'package:provider/provider.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
import 'logic/dash_upgrades.dart';
import 'logic/dash_counter.dart';
import 'pages/home_page.dart';
import 'pages/purchase_page.dart';
// Gives the option to override in tests.
class IAPConnection {
static InAppPurchase? _instance;
static set instance(InAppPurchase value) {
_instance = value;
}
static InAppPurchase get instance {
_instance ??= InAppPurchase.instance;
return _instance!;
}
}
void main() {
InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Dash Clicker',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Dash Clicker'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
typedef PageBuilder = Widget Function();
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
static final List<Widget> _widgetOptions = [
HomePage(),
PurchasePage(),
];
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<FirebaseNotifier>(
create: (_) => FirebaseNotifier()),
ChangeNotifierProvider<DashCounter>(create: (_) => DashCounter()),
ChangeNotifierProvider<DashUpgrades>(
create: (context) => DashUpgrades(
context.read<DashCounter>(),
context.read<FirebaseNotifier>(),
),
),
ChangeNotifierProvider<IAPRepo>(
create: (context) => IAPRepo(context.read<FirebaseNotifier>()),
),
ChangeNotifierProvider<DashPurchases>(
create: (context) => DashPurchases(
context.read<DashCounter>(),
context.read<FirebaseNotifier>(),
),
lazy: false,
),
],
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _widgetOptions[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.shop),
label: 'Purchase',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: (index) => setState(() => _selectedIndex = index),
),
),
);
}
}