-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
main.dart
112 lines (100 loc) · 2.97 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
111
112
import 'package:flutter/material.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:provider/provider.dart';
import 'logic/dash_counter.dart';
import 'logic/dash_purchases.dart';
import 'logic/dash_upgrades.dart';
import 'logic/firebase_notifier.dart';
import 'pages/home_page.dart';
import 'pages/purchase_page.dart';
import 'repo/iap_repo.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() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Dash Clicker',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Dash Clicker'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
typedef PageBuilder = Widget Function();
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
static final List<Widget> _widgetOptions = [
const HomePage(),
const 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>(),
context.read<IAPRepo>(),
),
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),
),
),
);
}
}