Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ This example uses a CustomScrollView, JSON Rest API, BottonNavigationBar,SliverL
* [*__http__*](https://pub.dartlang.org/packages/http)
* [*__webview_flutter__*](https://pub.dartlang.org/packages/webview_flutter)
* [*__shared_preferences__*](https://pub.dartlang.org/packages/shared_preferences)
* [*__share__*](https://pub.dartlang.org/packages/share)
* [*__cloud_firestore__*](https://pub.dartlang.org/packages/cloud_firestore)
* [*__uuid__*](https://pub.dartlang.org/packages/uuid)
* [*__dynamic_theme__*](https://pub.dartlang.org/packages/dynamic_theme)
* [*__share_plus__*](https://pub.dev/packages/share_plus)
* [*__cloud_firestore__*](https://pub.dev/packages/cloud_firestore)
* [*__uuid__*](https://pub.dev/packages/uuid)
* [*__adaptive_theme__*](https://pub.dev/packages/adaptive_theme)
* [*__flutter_picker__*](https://pub.dartlang.org/packages/flutter_picker)
* [*__flutter_material_color_picker__*](https://pub.dartlang.org/packages/flutter_material_color_picker)

Expand Down
4 changes: 2 additions & 2 deletions news_app/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 5391447fae6209bb21a89e6a5a6583cac1af9b4b
channel: beta
revision: 8defaa71a77c16e8547abdbfad2053ce3a6e2d5b
channel: stable

project_type: app
22 changes: 14 additions & 8 deletions news_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,33 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="News Daily"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.kaparray.newsapp;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
7 changes: 4 additions & 3 deletions news_app/lib/blocs/news_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import '../resources/repository.dart';
import 'package:rxdart/rxdart.dart';
import '../models/news_model.dart';
Expand All @@ -8,9 +9,9 @@ class NewsBloc {
final _newsSearchFetcher = PublishSubject<NewsModel>();
final _newsLikeFetcher = PublishSubject<NewsModel>();

Observable<NewsModel> get allNews => _newsFetcher.stream;
Observable<NewsModel> get searchNews => _newsSearchFetcher.stream;
Observable<NewsModel> get likeNews => _newsLikeFetcher.stream;
Stream<NewsModel> get allNews => _newsFetcher.stream;
Stream<NewsModel> get searchNews => _newsSearchFetcher.stream;
Stream<NewsModel> get likeNews => _newsLikeFetcher.stream;

fetchLikedNews() async {
NewsModel newsModel = await _repository.fetchLikedNews();
Expand Down
58 changes: 38 additions & 20 deletions news_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @dart=2.9
import 'package:flutter/material.dart';
import 'package:news_app/blocs/news_bloc.dart';
import 'package:news_app/ui/bottom_nav_bar.dart';
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:shared_preferences/shared_preferences.dart';

Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
Expand All @@ -10,8 +11,10 @@ int color;
String theme;

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initApp();
runApp(App());
final savedThemeMode = await AdaptiveTheme.getThemeMode();
runApp(App(savedThemeMode: savedThemeMode));
}

initApp() async {
Expand All @@ -32,12 +35,15 @@ initApp() async {

@immutable
class App extends StatefulWidget {
final AdaptiveThemeMode? savedThemeMode;

const App({Key key, this.savedThemeMode}) : super(key: key);

@override
createState() => AppState();
}

class AppState extends State<App> {
Brightness _brightness;

@override
void dispose() {
Expand All @@ -47,23 +53,35 @@ class AppState extends State<App> {

@override
Widget build(BuildContext context) {
if (theme == 'dark')
_brightness = Brightness.dark;
else if (theme == 'light') _brightness = Brightness.light;
final brightness = theme == 'dark' ? Brightness.dark : Brightness.light;
final seedColor = Color(color ?? 0xFF26A69A);

return DynamicTheme(
defaultBrightness: _brightness,
data: (brightness) => ThemeData(
brightness: _brightness, accentColor: Color(color ?? 0xFF26A69A)),
themedWidgetBuilder: (context, theme) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: BottomNavBar(),
theme: theme,
routes: {
"/news": (_) => BottomNavBar(),
},
);
});
return AdaptiveTheme(
light: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorSchemeSeed: seedColor,
),
dark: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: seedColor,
),
initial: widget.savedThemeMode ??
(brightness == Brightness.dark
? AdaptiveThemeMode.dark
: AdaptiveThemeMode.light),
builder: (themeData, darkTheme) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: BottomNavBar(),
theme: themeData,
darkTheme: darkTheme,
routes: {
"/news": (_) => BottomNavBar(),
},
);
},
);
}
}
1 change: 1 addition & 0 deletions news_app/lib/models/news_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
class NewsModel {
String status;
int totalResults;
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/resources/news_api_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'dart:async';
import 'package:http/http.dart' show Client;
import 'package:shared_preferences/shared_preferences.dart';
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/resources/repository.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'dart:async';

import 'news_api_provider.dart';
Expand Down
9 changes: 5 additions & 4 deletions news_app/lib/ui/bottom_nav_bar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:flutter/material.dart';
import 'package:news_app/ui/screens/liked_list.dart';
import 'package:news_app/ui/screens/news_list.dart';
Expand Down Expand Up @@ -25,16 +26,16 @@ class BottomNavBarState extends State<BottomNavBar> {
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.chrome_reader_mode), title: Text('News')),
icon: Icon(Icons.chrome_reader_mode), label: 'News'),
BottomNavigationBarItem(
icon: Icon(Icons.favorite_border),
title: Text('Favorit'),
label: 'Favorit',
activeIcon: Icon(Icons.favorite)),
BottomNavigationBarItem(
icon: Icon(Icons.settings), title: Text('Settings'))
icon: Icon(Icons.settings), label: 'Settings')
],
currentIndex: _currentItem,
fixedColor: Theme.of(context).accentColor,
selectedItemColor: Theme.of(context).accentColor,
onTap: _onItemTapped,
),
body: _listWidgets[_currentItem]);
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/screens/liked_list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:news_app/blocs/news_bloc.dart';
import 'package:news_app/ui/views/stream_builder.dart';
import 'package:flutter/material.dart';
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/screens/news_list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:news_app/blocs/news_bloc.dart';
import 'package:news_app/ui/views/search_bar.dart';
import 'package:news_app/ui/views/stream_builder.dart';
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/screens/serch_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:flutter/material.dart';
import 'package:news_app/blocs/news_bloc.dart';
import 'package:news_app/ui/views/stream_builder.dart';
Expand Down
33 changes: 21 additions & 12 deletions news_app/lib/ui/screens/settings_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @dart=2.9
import 'dart:convert';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
Expand Down Expand Up @@ -122,11 +123,10 @@ class SettingsState extends State<SettingsScreen> {
// Theme Logic
changeTheme(value) async {
SharedPreferences prefs = await _prefs;
DynamicTheme.of(context).setThemeData(ThemeData(
accentColor: Theme.of(context).accentColor,
brightness: Theme.of(context).brightness == Brightness.dark
? Brightness.light
: Brightness.dark));
if (AdaptiveTheme.of(context).mode == AdaptiveThemeMode.dark)
AdaptiveTheme.of(context).setLight();
else
AdaptiveTheme.of(context).setDark();
setState(() {
swTheme = value;
});
Expand Down Expand Up @@ -181,7 +181,7 @@ class SettingsState extends State<SettingsScreen> {

showDialog(
context: context,
child: SimpleDialog(
builder: (context) => SimpleDialog(
title: Text('Primary color', style: TextStyle(fontSize: 24)),
children: <Widget>[
MaterialColorPicker(
Expand Down Expand Up @@ -209,16 +209,25 @@ class SettingsState extends State<SettingsScreen> {
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
TextButton(
onPressed: () {
Navigator.pop(context, false);
},
child: Text("Cancel")),
FlatButton(
TextButton(
onPressed: () async {
DynamicTheme.of(context).setThemeData(ThemeData(
accentColor: local,
brightness: Theme.of(context).brightness));
AdaptiveTheme.of(context).setTheme(
light: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorSchemeSeed: local,
),
dark: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: local,
),
);
await prefs.setInt('color', local.value);
Navigator.pop(context, false);
},
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/screens/web_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:news_app/models/news_model.dart';
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/utils/back_to_start.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:flutter/material.dart';

backToStart(ScrollController scrollController) async {
Expand Down
3 changes: 2 additions & 1 deletion news_app/lib/ui/views/item_build.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @dart=2.9
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:news_app/models/news_model.dart';
import 'package:news_app/resources/news_api_provider.dart';
import 'package:news_app/ui/screens/web_view.dart';
import 'package:share/share.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/views/search_bar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:flutter/material.dart';
import 'package:news_app/ui/screens/serch_screen.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down
1 change: 1 addition & 0 deletions news_app/lib/ui/views/stream_builder.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @dart=2.9
import 'package:flutter/material.dart';
import 'package:news_app/ui/views/item_build.dart';

Expand Down
28 changes: 14 additions & 14 deletions news_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ description: A new Flutter project.
version: 1.0.5

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
rxdart: ^0.18.0
http: any
webview_flutter: ^0.3.0
url_launcher: ^4.2.0+1
shared_preferences: ^0.4.3
share: ^0.5.3
cloud_firestore: ^0.8.2+3
uuid: ^1.0.3
dynamic_theme: ^1.0.0
flutter_picker: ^1.0.6
flutter_material_color_picker: ^0.0.4
intl: ^0.15.7
rxdart: ^0.27.7
http: ^0.13.6
webview_flutter: ^4.2.2
url_launcher: ^6.2.6
shared_preferences: ^2.2.2
share_plus: ^8.0.2
cloud_firestore: ^4.15.9
uuid: ^3.0.7
adaptive_theme: ^2.3.1
flutter_picker: ^2.1.0
flutter_material_color_picker: ^1.1.0+2
intl: ^0.18.1


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^1.0.2

dev_dependencies:
flutter_test:
Expand Down