How can I hide the topbar of an app in flutter? I want to restrict users from closing the app.
Solution:
Add to dependencies window_manager: ^0.2.8
Import in main.dart import 'package:window_manager/window_manager.dart';
Place the following code
runApp(App());
windowManager.waitUntilReadyToShow().then((_) async{
await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
});
Related
I am building a flutter app which has these two plugins 1) local_auth 2) flutter_bar_code and they both use different main activities , for local auth the MainActivity.kt is like
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
}
and for flutter bar code scanner the MainActivity.tk is like
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
Flutter has a single MainActivity file. if you want to add more screen then please read doc and blogs here is one for you: Add Multiple screen
does anyone know how to achieve a CircularProgressIndicator() as on the screenshot below in Flutter?
That's the IOS equivalent of the CircularProgressIndicator(). You can use CupertinoActivityIndicator. Here is a YouTube video by the Google team on how to use it.
You have to import cupertino first:
import 'package:flutter/cupertino.dart';
...
return CupertinoActivityIndicator()
Result:
How to disable screenshot in flutter? I have Kotlin file instead of MainActivity.java file. Please suggest full code with path where I need to change for disable screenshot in my app.
package com.quotster.untitled
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
If you want to do that in Android only you can use flutter_windowmanager and add FLAG_SECURE.
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
I tried searching for any documentation / search results on this, but I couldn't find any, is it possible to have a macOS desktop app created with flutter always on top on macOS?
The default macOS Flutter application is just a standard NSWindow containing a Flutter view, so you would make it always on top the same way you would any other macOS application window, using NSWindowLevel.
There are two ways you can get to the window in your Flutter app:
Drectly in MainFlutterWindow.swift, if your want it to always be on top.
Via a plugin if you want to change it dynamically. FlutterPluginRegistrar has a view property that gives you the Flutter view, then you can get that view's window.
You can do this easily with the window_manager package.
import 'package:window_manager/window_manager.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
windowManager.setAlwaysOnTop(true);
runApp(const MyApp());
}
I need to know is there any way to perform a task during splash screen is visible in flutter. I know how to add splash screen in flutter but I don't know how to perform background operations during splash screen is visible. I can't find anything on the internet, please help.
Yes, yes you can. The main() function can actually be tagged as async, so you can do whatever you need to do before running runApp(...) in the main() method body, even asynchronously. This way, the splash screen will be shown until your asynchronous result is retrieved, before calling runApp(...). For example:
Future<void> main() async {
// Do whatever you need to do here
final home = await setHomeWidgetDependingOnLoginStatus();
return runApp(MyApp(home: home));
}
The animated_splash_screen package does this worderfully. add it to your pubspec.yml
animated_splash_screen: ^1.1.0
AnimatedSplashScreen.withScreenFunction(
splash: 'images/splash.png',
screenFunction: () async{
// Your code here
return MainScreen();
},
splashTransition: SplashTransition.rotationTransition,
pageTransitionType: PageTransitionType.scale,
)
This will load and hold you splash screen until your function is complete.
Your function has to return a widget, in this case is your home screen. This also allows for dynamic routing depending on your data eg, is user logged in.