How to use FileSystemEntity.watch() in flutter? - flutter

I'm building a desktop application, mainly for Windows platform. I want to track events like create, delete in a directory using flutter. I came across the FileSystemEntity.watch() method but I'm unable to implement that. Can someone share the full example codebase for watching a directory?

Just watch the folder to receive a stream of events. Normally, you then listen to the stream to receive each event as it happens.
import 'dart:io';
void main() {
final tempFolder = File('D:\\temp');
tempFolder.watch().listen((event) {
print(event);
});
}
Prints:
FileSystemCreateEvent('D:\temp\New Text Document.txt')
FileSystemMoveEvent('D:\temp\New Text Document.txt', 'D:\temp\foo.txt')
FileSystemCreateEvent('D:\temp\New folder')
FileSystemMoveEvent('D:\temp\New folder', 'D:\temp\bar')
FileSystemDeleteEvent('D:\temp\bar')
FileSystemDeleteEvent('D:\temp\foo.txt')
for the creation, rename and deletion of a plain file and folder.
(You tagged the question as Flutter Web even though you are on desktop. You obviously cannot use dart:io in web.)

Related

Hive adapters and boxes with Get_it how should i regester them into getit

I have always issues with hive boxies instances and the error of not initilizing the box or adapter
so I decided to register them in one place and use it all over place .but I don't event know how to use and register adapters and box
I have nothing tried because I don't know how to implement that
The recommended place to register an adapter using Hive.registerAdapter() is immediately after the Hive.initFlutter() finishes, then open your box with the object type that you made the adapter for, like this:
Future<void> main() async {
await Hive.initFlutter();
Hive.registerAdapter<Question>(QuestionAdapter());
await Hive.openBox<Question>("questions");
runApp(MyApp());
}
now the "questions" box will be available to use directly across your whole app by :
Hive.box("questions");

What are the permissions necessary for an 'Always-On-Display' app?

I would like to make an AOD (always on display) app using Flutter.
I just want to know what are the permissions that my app requires in order to be functional.
I didn't start the proj. yet, therefore I don't even have any code to share.
Would start the proj. after I get my answers.
Always on display,you can achieve it by using this package
https://pub.dev/packages/wakelock
you can easily call like this and achieve your goal.like follows
import 'package:wakelock/wakelock.dart';
// ...
// The following line will enable the Android and iOS wakelock.
Wakelock.enable();
// The next line disables the wakelock again.
Wakelock.disable();

Is it possible to import a single file from material library to access its private fields?

I want to access a file from material.dart library ('src/material/search.dart';) so that I can access private fields (_somethingsomething) in it to create a widget.
I read a bit about part/part of and so on, but it seems that I am not using it properly.
Is something like this possible?
Steps: Copying a file from Flutter into your own app.
Create a file search_copy.dart, and copy the content of material's search.dart.
Remove the internal imports used in the file.
Instead add the import import 'package:flutter/material.dart' to search_copy.dart
Modify the new file according to your needs, like exposing the private field.
Import the file with a prefix import 'search_copy.dart' as search; so you don't get import conflicts with material itself.
When you want to access it do so like search.showSearch(context: context, delegate: delegate)
Note: The search.dart file is part of flutter itself which is BSD-licensed. (https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/search.dart)
License:
https://github.com/flutter/flutter/blob/master/packages/flutter/LICENSE
The answer is NO. And probably there is a reason why these fields are private since package owners (in this case, framework maintainers) do not want the developer to use the variables directly or change them in any way.
If you would like to adjust the code for the component in the material library, you could:
a) Create an issue under flutter repository and explain why you need to access the fields, maybe even create a POC by forking the repository and implementing your changes. The Flutter team may approve this and your changes will be a part of the framework - that's the beauty of open-source! However, there is no guarantee that it will happen.
b) Copy-paste the search.dart code to your project and adjust whatever is needed. This is a faster solution to your problem, however, now you should maintain this code by yourself, you would need to keep this component in sync with any Flutter update.

How to remove # symbol from flutter web app url

As the time am asking this question, is there any official or an update that enables me to remove the # symbol in the flutter web app url.
I have seen some work arounds to achieve this but they end up causing other issues like: people not able to access the webpage without the hash # in the url
From this answer
There is a package call url_strategy in pub.dev. You only need to import in into pubspec.yaml and copy the code below into your main.dart file. It will remove the # in your flutter web URL
import 'package:url_strategy/url_strategy.dart';
void main() {
// Here we set the URL strategy for our web app.
// It is safe to call this function when running on mobile or desktop as well.
setPathUrlStrategy();
runApp(MyApp());
}

Agora SDK not working in Windows Build. VideoSurface.cs always gets tmpi = -1 in Update

I am trying to implement Screen broadcast with Unity using the Agora Video Chat SDK for Unity. I used this source, which doesn't work initially. But after modifying the code as below, I am able to receive my own stream through the server, inside Unity editor (2019.1.2f1).
//Adding inside Start
mRtcEngine.OnJoinChannelSuccess = Joined;
}
private void Joined(string channelName, uint uid, int elapsed)
{
var videoSource = FindObjectOfType<VideoSurface>();
videoSource.SetForUser(uid);
videoSource.SetEnable(true);
}
But nothing happens in the Windows build. I checked the VideoSurface.cs file. I am continuously getting tmpi = -1 inside Update. What could be the reason?
PS. I check all firewall permissions for the build. Also, the user is able to join the channel. It's just the stream that is not being received. Help appreciated.
You shouldn't need to modify the code like that. And also, in the code above you register the callback for the local user. If you want to show remote user's video, you should register the callback for OnUserJoined().
Have you seen the tutorial about the Screensharing? https://www.agora.io/en/blog/how-to-broadcast-your-screen-with-unity3d-and-agora/
Please try that. If you are still confused, you may take a look at this github repo. It has different contents to share, but the concept and Agora API usage are pretty much the same.