-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.dart
178 lines (171 loc) · 5.69 KB
/
settings.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:flutter/material.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:news_app/main.dart';
import 'package:news_app/news_sources.dart';
import 'package:news_app/services/rss_feed.dart';
import 'package:news_app/services/theme_manager.dart';
import 'package:news_app/utils/utils.dart';
class Settings extends StatefulWidget {
@override
_SettingsState createState() => _SettingsState();
}
class _SettingsState extends State<Settings> {
String sourceName = Rss.instance.source.name;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Ayarlar"),
),
body: ListView(
children: [
ListTile(
title: Text("Renk şeması"),
subtitle: ThemeManager.instance.getTheme() ==
ThemeManager.instance.lightTheme
? Text("Açık tema")
: Text("Karanlık tema"),
trailing: Switch(
value: ThemeManager.instance.getTheme() ==
ThemeManager.instance.lightTheme,
onChanged: (value) => ThemeManager.instance.switchTheme(),
activeColor: Colors.indigoAccent,
inactiveThumbColor: Colors.blueGrey,
),
),
ListTile(
title: Text("Haber kaynağı"),
subtitle: Text(sourceName),
onTap: () => showMaterialModalBottomSheet(
expand: false,
context: context,
backgroundColor:
ThemeManager.instance.getTheme().dividerColor,
builder: (context) => SourceSelector(
notifyParent: refresh,
),
)),
ListTile(
title: Text("Hesaptan çık"),
subtitle: Text(FirebaseAuth.instance.currentUser.displayName ??
FirebaseAuth.instance.currentUser.email),
trailing: Icon(Icons.logout),
onTap: () async {
if (FirebaseAuth
.instance.currentUser.providerData[0].providerId ==
"google.com") {
await GoogleSignIn().signOut();
}
await FirebaseAuth.instance.signOut();
Utils.pushAndRemove(context, Splash());
},
),
ListTile(
title: Text("Lisanslar"),
trailing: Icon(Icons.book),
onTap: () => showMaterialModalBottomSheet(
context: context, builder: (context) => AboutPage()),
),
],
),
);
}
void refresh(String name) {
setState(() {
sourceName = name;
});
}
}
class SourceSelector extends StatelessWidget {
final Function notifyParent;
const SourceSelector({Key key, @required this.notifyParent})
: super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: ThemeManager.themeData == ThemeManager.instance.lightTheme
? Colors.white
: Colors.black.withAlpha(100),
child: SafeArea(
top: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
for (MyRssSource source in sources)
_builder(context, source.name, source.key)
],
),
));
}
ListTile _builder(BuildContext context, String name, String key) {
return ListTile(
title: Text(name),
trailing: key == Rss.instance.source.key ? Icon(Icons.check) : null,
onTap: () async {
Rss.changeSource(key);
Navigator.of(context).pop();
notifyParent(name);
},
);
}
}
class AboutPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height / 3,
child: SafeArea(
top: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 80,
width: 80,
child: Image.asset(
"assets/icons/icons8-news-512.png",
scale: 5,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Haber Uygulaması",
style: TextStyle(fontSize: 20),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Bu uygulama Ensar Emir EROL tarafından Flutter ile yapılmıştır",
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text(
"Lisanslar",
style: TextStyle(fontSize: 15),
),
onPressed: () => showLicensePage(
context: context,
applicationName: "Haber Uygulaması",
applicationVersion: "1.0",
applicationIcon: Image.asset(
"assets/icons/icons8-news-512.png",
scale: 5,
)),
),
)
],
),
));
}
}