make all possible fields private

update dependencies
try to infer the prefix of the server url
display display size dependent amount on shuffle page
This commit is contained in:
lukas-heiligenbrunner 2022-08-25 19:48:09 +02:00
parent 74e2afee98
commit bf070ff99a
13 changed files with 153 additions and 131 deletions

View File

@ -17,18 +17,14 @@ class DrawerPage extends StatefulWidget {
enum Section { HOME, SHUFFLE, LOGOUT }
class _DrawerPageState extends State<DrawerPage> {
Section sec = Section.HOME;
Section _sec = Section.HOME;
@override
Widget build(BuildContext context) {
Widget body;
String title;
/// You can easily control the section for example inside the initState where you check
/// if the user logged in, or other related logic
switch (sec) {
/// Display the home section, simply by
switch (_sec) {
case Section.HOME:
body = const VideoFeed();
title = widget.title;
@ -45,13 +41,13 @@ class _DrawerPageState extends State<DrawerPage> {
break;
}
var loginctx = LoginContext.of(context);
final loginCtx = LoginContext.of(context);
return Scaffold(
appBar: AppBar(title: Text(title), actions: [
IconButton(
onPressed: () {
loginctx.onLoggin(false);
loginCtx.onLoggin(false);
Token.getInstance().setToken("", "");
},
icon: const Icon(Icons.logout))
@ -64,7 +60,7 @@ class _DrawerPageState extends State<DrawerPage> {
leading: const Icon(Icons.home),
onTap: () {
setState(() {
sec = Section.HOME;
_sec = Section.HOME;
});
Navigator.pop(context);
},
@ -74,7 +70,7 @@ class _DrawerPageState extends State<DrawerPage> {
leading: const Icon(Icons.update),
onTap: () {
setState(() {
sec = Section.SHUFFLE;
_sec = Section.SHUFFLE;
});
Navigator.pop(context);
},
@ -84,7 +80,7 @@ class _DrawerPageState extends State<DrawerPage> {
leading: const Icon(Icons.settings),
onTap: () {
setState(() {
sec = Section.LOGOUT;
_sec = Section.LOGOUT;
});
Navigator.pop(context);
},

View File

@ -3,26 +3,18 @@ import 'package:openmediacentermobile/log/log.dart';
import 'package:openmediacentermobile/login/login_screen.dart';
import 'DrawerPage.dart';
import 'api/token.dart';
import 'login/logincontext.dart';
import 'video_feed.dart';
// class App extends StatefulWidget {
// const App({Key? key}) : super(key: key);
// @override
// State<StatefulWidget> createState() => AppState();
// }
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var loginctx = LoginContext.of(context);
var loginCtx = LoginContext.of(context);
Log.d("We are logged in: ${loginctx.LoggedIn}");
Log.d("We are logged in: ${loginCtx.loggedIn}");
if (!loginctx.LoggedIn) {
if (!loginCtx.loggedIn) {
return const MaterialApp(home: LoginScreen());
} else {
return const MaterialApp(

View File

@ -18,11 +18,14 @@ class _LoginScreenState extends State<LoginScreen> {
final TextEditingController _domainTextController = TextEditingController();
final TextEditingController _passwordTextController = TextEditingController();
String error = "";
bool _loginActive = false;
Future<String> login(String password, String domain) async {
Log.i("logging in...");
// final compl = Completer<String>();
final resp = await http.post(
http.Response resp;
try {
resp = await http.post(
Uri.parse(domain + '/api/login/login'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
@ -31,9 +34,12 @@ class _LoginScreenState extends State<LoginScreen> {
'Password': password,
}),
);
} catch (e) {
return "error" + e.toString();
}
if (resp.statusCode != 200) {
return resp.body;
return "error" + resp.body;
// compl.complete(resp.body);
} else {
@ -44,13 +50,7 @@ class _LoginScreenState extends State<LoginScreen> {
LoginContext.of(context).onLoggin(true);
return "";
// compl.complete("");
}
// LoginContext.of(context).onLoggin(true);
// return compl.future;
}
@override
@ -130,16 +130,26 @@ class _LoginScreenState extends State<LoginScreen> {
backgroundColor: const Color(0xff4c505b),
child: IconButton(
color: Colors.white,
onPressed: () {
onPressed: () async {
Log.d("clickkked");
final pwd = _passwordTextController.value.text;
final domain = _domainTextController.value.text;
login(pwd, domain).then((value) {
if (value != "") {
setState(() {
error = value;
});
var err = "";
if (domain.startsWith("https://") || domain.startsWith("http://")) {
err = await login(pwd, domain);
if (err.isEmpty) return;
} else {
// try to auto infering domain prefix
err = await login(pwd, "https://" + domain);
if (err.isEmpty) return;
err = await login(pwd, "http://" + domain);
if (err.isEmpty) return;
}
Log.i(err);
setState(() {
error = err;
});
},
icon: const Icon(

View File

@ -12,8 +12,8 @@ class LoginContainer extends StatefulWidget {
}
class _LoginContainerState extends State<LoginContainer> {
bool loggedIn = false;
bool loading = true;
bool _loggedIn = false;
bool _loading = true;
@override
void initState() {
@ -24,13 +24,13 @@ class _LoginContainerState extends State<LoginContainer> {
Log.i("The token value is $value");
if (value != null) {
setState(() {
loggedIn = true;
loading = false;
_loggedIn = true;
_loading = false;
});
} else {
setState(() {
loggedIn = false;
loading = false;
_loggedIn = false;
_loading = false;
});
}
});
@ -39,8 +39,8 @@ class _LoginContainerState extends State<LoginContainer> {
@override
Widget build(BuildContext context) {
return LoginContext(
LoggedIn: loggedIn,
child: loading
loggedIn: _loggedIn,
child: _loading
? MaterialApp(
home: Container(
color: Colors.white,
@ -49,9 +49,9 @@ class _LoginContainerState extends State<LoginContainer> {
)
: widget.child,
onLoggin: (bool login) {
if (loggedIn != login) {
if (_loggedIn != login) {
setState(() {
loggedIn = login;
_loggedIn = login;
});
}
},
@ -63,11 +63,11 @@ class LoginContext extends InheritedWidget {
const LoginContext(
{Key? key,
required Widget child,
required this.LoggedIn,
required this.loggedIn,
required this.onLoggin})
: super(key: key, child: child);
final bool LoggedIn;
final bool loggedIn;
final void Function(bool) onLoggin;
static LoginContext of(BuildContext context) {
@ -79,6 +79,6 @@ class LoginContext extends InheritedWidget {
@override
bool updateShouldNotify(LoginContext old) {
return LoggedIn != old.LoggedIn;
return loggedIn != old.loggedIn;
}
}

View File

@ -7,7 +7,6 @@ import 'log/log.dart';
import 'login/logincontext.dart';
import 'platform.dart';
// main app entry point
void main() async {
Log.i("App init!");
DartVLC.initialize();

View File

@ -16,10 +16,8 @@ class PreviewGrid extends StatefulWidget {
class _PreviewGridState extends State<PreviewGrid> {
late Future<List<VideoT>> _data;
Image? _previewImage;
@override
void initState() {
super.initState();
@ -28,7 +26,7 @@ class _PreviewGridState extends State<PreviewGrid> {
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
final double width = MediaQuery.of(context).size.width;
return FutureBuilder<List<VideoT>>(
future: _data, // a previously-obtained Future<String> or null

View File

@ -12,9 +12,9 @@ import 'platform.dart';
class VideoT {
int id;
String title;
double Ratio;
double ratio;
VideoT(this.title, this.id, this.Ratio);
VideoT(this.title, this.id, this.ratio);
factory VideoT.fromJson(dynamic json) {
return VideoT(json['MovieName'] as String, json['MovieId'] as int, (json['Ratio'] as num).toDouble());
@ -109,7 +109,7 @@ class _PreviewTileState extends State<PreviewTile> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoScreen(MetaData: widget.dta),
builder: (context) => VideoScreen(metaData: widget.dta),
),
);
},

View File

@ -3,7 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:openmediacentermobile/preview_tile.dart';
import 'preview_tile.dart';
import 'api/api.dart';
import 'platform.dart';
@ -18,8 +18,8 @@ class ShuffleScreen extends StatefulWidget {
class _ShuffleScreenState extends State<ShuffleScreen> {
late Future<List<VideoT>> _data;
Future<List<VideoT>> loadData() async {
final data = await API.query("video", "getRandomMovies", {'Number': 4, 'Seed': Random().nextInt(0x7fffffff)});
Future<List<VideoT>> loadData(int nr) async {
final data = await API.query("video", "getRandomMovies", {'Number': nr, 'Seed': Random().nextInt(0x7fffffff)});
final d = jsonDecode(data);
@ -32,7 +32,11 @@ class _ShuffleScreenState extends State<ShuffleScreen> {
void initState() {
super.initState();
_data = loadData();
_data = Future.delayed(Duration.zero).then((_) {
double width = MediaQuery.of(context).size.width;
return loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2);
});
}
@override
@ -52,7 +56,7 @@ class _ShuffleScreenState extends State<ShuffleScreen> {
mainAxisSpacing: 4,
crossAxisSpacing: 4,
padding: EdgeInsets.all(5),
itemCount: 4,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return PreviewTile(dta: snapshot.data![index]);
},
@ -63,7 +67,7 @@ class _ShuffleScreenState extends State<ShuffleScreen> {
TextButton.icon(
onPressed: () {
setState(() {
_data = loadData();
_data = loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2);
});
},
icon: const Icon(Icons.update),

View File

@ -14,19 +14,19 @@ import 'log/log.dart';
import 'platform.dart';
class VideoScreen extends StatefulWidget {
const VideoScreen({Key? key, required this.MetaData}) : super(key: key);
final VideoT MetaData;
const VideoScreen({Key? key, required this.metaData}) : super(key: key);
final VideoT metaData;
@override
State<VideoScreen> createState() => _VideoScreenState();
}
class _VideoScreenState extends State<VideoScreen> {
Player? player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
Player? _player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
ChewieController? _chewieController;
void loadData() async {
final data = await API.query("video", "loadVideo", {'MovieId': widget.MetaData.id});
final data = await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
final d = jsonDecode(data);
@ -41,7 +41,7 @@ class _VideoScreenState extends State<VideoScreen> {
if (isDesktop()) {
final media2 = Media.network(path);
player?.open(
_player?.open(
media2,
autoStart: true, // default
);
@ -70,9 +70,9 @@ class _VideoScreenState extends State<VideoScreen> {
if(isDesktop()){
RawKeyboard.instance.addListener((value) {
if (value.logicalKey == LogicalKeyboardKey.arrowRight) {
player?.seek(player!.position.position! + const Duration(seconds: 5));
_player?.seek(_player!.position.position! + const Duration(seconds: 5));
} else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) {
player?.seek(player!.position.position! + const Duration(seconds: -5));
_player?.seek(_player!.position.position! + const Duration(seconds: -5));
}
});
}
@ -87,7 +87,7 @@ class _VideoScreenState extends State<VideoScreen> {
void dispose() {
super.dispose();
if (isDesktop()) {
player?.dispose();
_player?.dispose();
} else {
_chewieController?.videoPlayerController.dispose();
_chewieController?.dispose();
@ -98,7 +98,7 @@ class _VideoScreenState extends State<VideoScreen> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.MetaData.title),
title: Text(widget.metaData.title),
),
body: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()),
);
@ -106,10 +106,9 @@ class _VideoScreenState extends State<VideoScreen> {
Widget videoDesktop() {
return Video(
player: player,
player: _player,
scale: 1.0, // default
showControls: true,
playlistLength: 1, // default
showControls: true
);
}

View File

@ -8,6 +8,8 @@
#include <dart_vlc/dart_vlc_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dart_vlc_registrar =
@ -16,4 +18,10 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}

View File

@ -5,6 +5,8 @@
list(APPEND FLUTTER_PLUGIN_LIST
dart_vlc
flutter_secure_storage_linux
screen_retriever
window_manager
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@ -42,7 +42,7 @@ packages:
name: chewie
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
version: "1.3.4"
clock:
dependency: transitive
description:
@ -63,35 +63,35 @@ packages:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.1"
version: "0.17.2"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
dart_vlc:
dependency: "direct main"
description:
name: dart_vlc
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.9"
version: "0.3.0"
dart_vlc_ffi:
dependency: transitive
description:
name: dart_vlc_ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5+1"
version: "0.1.8"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.3"
version: "4.0.0"
device_info_plus_linux:
dependency: transitive
description:
@ -112,7 +112,7 @@ packages:
name: device_info_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0+1"
version: "2.6.1"
device_info_plus_web:
dependency: transitive
description:
@ -140,14 +140,14 @@ packages:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "1.2.1"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
@ -159,28 +159,35 @@ packages:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "2.0.1"
flutter_native_view:
dependency: transitive
description:
name: flutter_native_view
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
version: "6.0.0"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
@ -208,7 +215,7 @@ packages:
name: flutter_staggered_grid_view
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1"
version: "0.6.2"
flutter_test:
dependency: "direct dev"
description: flutter
@ -232,14 +239,14 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.4"
version: "0.13.5"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
version: "4.0.1"
js:
dependency: transitive
description:
@ -253,7 +260,7 @@ packages:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "2.0.0"
logger:
dependency: "direct main"
description:
@ -302,49 +309,49 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
version: "2.0.11"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
version: "2.0.19"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.0.11"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "2.1.7"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.0.6"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.4"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.0.7"
platform:
dependency: transitive
description:
@ -372,7 +379,14 @@ packages:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
version: "6.0.3"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sky_engine:
dependency: transitive
description: flutter
@ -426,7 +440,7 @@ packages:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
vector_math:
dependency: transitive
description:
@ -434,55 +448,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
very_good_analysis:
dependency: transitive
description:
name: very_good_analysis
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
video_player:
dependency: "direct main"
description:
name: video_player
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
version: "2.4.7"
video_player_android:
dependency: transitive
description:
name: video_player_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.2"
version: "2.3.9"
video_player_avfoundation:
dependency: transitive
description:
name: video_player_avfoundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
version: "2.3.5"
video_player_platform_interface:
dependency: transitive
description:
name: video_player_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.1"
version: "5.1.4"
video_player_web:
dependency: transitive
description:
name: video_player_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7"
version: "2.0.12"
wakelock:
dependency: transitive
description:
name: wakelock
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1+2"
version: "0.6.2"
wakelock_macos:
dependency: transitive
description:
@ -517,14 +524,21 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.1"
version: "2.6.1"
window_manager:
dependency: transitive
description:
name: window_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.6"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+1"
version: "0.2.0+2"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0"
dart: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0"

View File

@ -34,12 +34,12 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
flutter_secure_storage: ^5.0.2
flutter_secure_storage: ^6.0.0
logger: ^1.1.0
http: ^0.13.4
flutter_staggered_grid_view: ^0.6.1
dart_vlc: ^0.1.9
device_info_plus: ^3.2.3
dart_vlc: ^0.3.0
device_info_plus: ^4.0.0
video_player: ^2.3.0
chewie: ^1.3.2
@ -52,7 +52,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
flutter_lints: ^2.0.1
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec