This question already has answers here:
Make flutter application fullscreen
(13 answers)
Closed 2 years ago.
I have tried different things from different sites and articles but i cannot get rid the black bar on top
it's been asked here
tl;dr
add this piece code to the main function, before runApp()
SystemChrome.setEnabledSystemUIOverlays([])
code:
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays(<SystemUiOverlay>[]);
runApp(MyApp());
}
the screen you want to make will be like this
class SplashScreen extends StatefulWidget {
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
#override
Widget build(BuildContext context) {
return Scaffold();
}
}
result:
without SystemChrome.setEnabledSystemUIOverlays([]):
Related
In my Flutter app (Android and iOS only), I want to add a widget that will overlay the entire app.
Here is what my main class looks like:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/someroute"
onGenerateRoute: MyRouteManager.generateRoute
);
}
I tried to follow that example, but my problem is that I use named routes in my app, and I don't know how to overlay a widget above my entire app in that case.
I also tried the overlay_screen plugin, but it has some bugs and does not allow the user to interact with the screen below the overlay screen.
How can I achieve that?
Thanks.
try this out:
Navigator.pushNamed(context, '/name_of_your_second_page');
This question already has answers here:
Passing data to StatefulWidget and accessing it in it's state in Flutter
(7 answers)
Closed 1 year ago.
I have this Stateful class and I wanna took "Data" from Stateful class to State class
Here is my code:
class PlayMode extends StatefulWidget {
final Data data;
PlayMode({this.data}); // Pass this to State class
#override
State<StatefulWidget> createState() {
return new PlayModeState();
}
}
How it can be done?
In your PlayModeState class, simply use
widget.data
When I click a different window in my desktop manager, my flutter desktop app is no longer the active / focused window (title bar goes grey).
How can I listen for this event?
I've tried a MouseRegion but it seems that onExit isn't fired when the mouse leaves the window.
I'm specifically looking for a Linux and Windows solution but would love something that also works on Mac.
There is not yet an event wired through to Dart for that in any of the desktop embeddings. Currently the only way to do that would be to write a plugin that sent a custom message for window activation and deactivation.
You can use window_manager, which helps to find the focus and inactive/blur state
import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with WindowListener {
#override
void initState() {
windowManager.addListener(this);
super.initState();
}
#override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
#override
Widget build(BuildContext context) {
// ...
}
#override
void onWindowFocus() {
// do something when app gets into focus state
}
#override
void onWindowBlur() {
// do something when app gets into inactive/blur state
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How can I configure the sensors (Accelerometer or gyroscope) to do something when the user shakes or rotate the phone?
I want to show a new string each time the user shakes the phone.
Also I need a button to start and finish the sensors "action". Thanks!!!!!!
Use flutter_shake_plugin and you can try something like this:
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_shake_plugin/flutter_shake_plugin.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
FlutterShakePlugin _shakePlugin;
#override
void initState() {
super.initState();
_shakePlugin = FlutterShakePlugin(
onPhoneShaken: (){
//do stuff on phone shake
print('phone shakes');
},
)..startListening();
}
#override
void dispose() {
super.dispose();
_shakePlugin.stopListening();
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Shake Plugin example app'),
),
),
);
}
}
If you want to see live example. Take a look at this link I've implemented in one of my apps.
am looking to clean my code
such : menu items it's at every page how to set it
into one dart file and include it later !!
like PHP
<?php include('1.dart'); ?>
am looking to do it with duplicate Containers at pages
that's possible ?
Not exactly like that,but you can make a Widget that suits your needs,then create an instance of it in other widgets by importing the .dart file and using it without writing all its code.
I can give you an example:
I need a specific Container or Card of any other widget that will need to be replicated.What I would do in this scenerio is create a new .dart file and name it after what I need-for example a Social Network post:
class Post extends StatefulWidget {
Post();
#override
_PostState createState() => _PostState();
}
class _PostState extends State<Post> {
_PostState(){
}
#override
Widget build(BuildContext context) {
}
I would write the code that I need to replicate in here then import it inside my home.dart like this:
import 'package:app/widgets/post.dart';
class Home extends StatefulWidget {
Home();
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
_HomeState(){
}
#override
Widget build(BuildContext context) {
Post post = new Post(//here you can construct the post with your data);
}