当看到打开的应用程序时,不显示 flutter 应用程序名称
flutter app name doesn't show when see opened apps
我有我的应用程序,我已经更改了它的名称并正确显示,但是当您在 phone 上看到打开的应用程序时,该应用程序没有名称但是当您在应用程序列表中看到它的图标时它显示正确你会从图片中得到想法
在 5 种不同的设备上测试
应用列表中的应用图标(正确显示)
应用程序名称,同时看到打开的应用程序
我不知道为什么会这样我会和你分享我的清单请告诉我如何解决这个问题
这是AndroidManifest.xml
package="com.eco.cat">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="EcoCat"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
我的main.dart
import 'Front-end/home/Companies.dart';
import 'Front-end/search/Search.dart';
import 'Front-end/settings/Settings.dart';
import 'file:///D:/programming/Android_Development/Projects/coupon_app/lib/reusable_widgets/functions/Device_Information.dart';
import 'package:app/reusable_widgets/logic/Check_SiteStatus.dart';
import 'package:app/reusable_widgets/logic/Responsiveness-Controller.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_phoenix/flutter_phoenix.dart';
import 'package:provider/provider.dart';
import 'Themes/DarkThemeProvider.dart';
import 'Themes/DarkThemeStyle.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp , DeviceOrientation.portraitDown])
.then((_) => runApp(
Phoenix(
child: MyApp(),
),
),
);
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
DarkThemeProvider themeChangeProvider = new DarkThemeProvider();
@override
void initState() {
super.initState();
getCurrentAppTheme();
}
void getCurrentAppTheme() async {
themeChangeProvider.darkTheme =
await themeChangeProvider.darkThemePreference.getTheme();
}
Widget build(BuildContext context) {
return
ChangeNotifierProvider(
create: (_) {
return themeChangeProvider;
},
child: Consumer<DarkThemeProvider>(
builder: (BuildContext context, value, Widget child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: Styles.themeData(themeChangeProvider.darkTheme, context),
home: MyHomePage(),
);
},
),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
//bottom navbar items to build body
int _currentIndex = 1;
final List<Widget> _children = [
Search(),
CompaniesPage(),
Settings(),
];
@override
Widget build(BuildContext context) {
//checks web server status
checkSiteStatus(context);
Color themeColor = Theme.of(context).backgroundColor;
void changePage(int index){
setState(() {
_currentIndex = index;
});
}
//setting app name based on current page
String title = '';
if(_currentIndex == 0){
title = 'ابحث باستخدام التصنيفات';
}else if(_currentIndex == 1){
title = 'الشركات';
}else if(_currentIndex == 2){
title = 'الاعدادات';
}
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
bottomOpacity: 0.0,
elevation: 0.0,
title: new Center(
child: Text('$title',
style: TextStyle(color: Colors.white ,
fontSize: DeviceInformation(context).width * ResponsivenessController(context).responsiveFont
),
),
),
),
body: _children[_currentIndex],
bottomNavigationBar: CurvedNavigationBar(
index: _currentIndex,
color: themeColor,
backgroundColor: Colors.cyan,
height: 75.0,
items:<Widget>[
Icon(Icons.search, size: DeviceInformation(context).height * ResponsivenessController(context).responsiveNavIcons),
Icon(Icons.home, size: DeviceInformation(context).height * ResponsivenessController(context).responsiveNavIcons),
Icon(Icons.settings, size: DeviceInformation(context).height * ResponsivenessController(context).responsiveNavIcons),
],
onTap: changePage,
),
);
}
}
使用 MaterialApp 并为其设置标题。像这样:
import 'package:flutter/material.dart';
main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Your_App_Name',
home: DashboardPage(),
);
}
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Home sweet home"),
),
body: Home(),
);
你最好检查 appbar
你是否已经有一个标题。 title
可能也会从 main.dart
中消失
MaterialApp
是使用 Material 设计的 Flutter 应用程序的入口点,因此它应该只在 MyApp
小部件中声明一次。它的文档是 here.
如文档中所述,Material应用程序的 title 属性 是看到打开的应用程序时出现的那个。 AndroidManifest 中的 android:label
是显示在主屏幕上的标题。
您应该使用以下代码设置标题
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: Styles.themeData(themeChangeProvider.darkTheme, context),
home: MyHomePage(),
title: "EcoCat",
);
我有我的应用程序,我已经更改了它的名称并正确显示,但是当您在 phone 上看到打开的应用程序时,该应用程序没有名称但是当您在应用程序列表中看到它的图标时它显示正确你会从图片中得到想法
在 5 种不同的设备上测试
应用列表中的应用图标(正确显示)
应用程序名称,同时看到打开的应用程序
我不知道为什么会这样我会和你分享我的清单请告诉我如何解决这个问题
这是AndroidManifest.xml
package="com.eco.cat">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="EcoCat"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
我的main.dart
import 'Front-end/home/Companies.dart';
import 'Front-end/search/Search.dart';
import 'Front-end/settings/Settings.dart';
import 'file:///D:/programming/Android_Development/Projects/coupon_app/lib/reusable_widgets/functions/Device_Information.dart';
import 'package:app/reusable_widgets/logic/Check_SiteStatus.dart';
import 'package:app/reusable_widgets/logic/Responsiveness-Controller.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_phoenix/flutter_phoenix.dart';
import 'package:provider/provider.dart';
import 'Themes/DarkThemeProvider.dart';
import 'Themes/DarkThemeStyle.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp , DeviceOrientation.portraitDown])
.then((_) => runApp(
Phoenix(
child: MyApp(),
),
),
);
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
DarkThemeProvider themeChangeProvider = new DarkThemeProvider();
@override
void initState() {
super.initState();
getCurrentAppTheme();
}
void getCurrentAppTheme() async {
themeChangeProvider.darkTheme =
await themeChangeProvider.darkThemePreference.getTheme();
}
Widget build(BuildContext context) {
return
ChangeNotifierProvider(
create: (_) {
return themeChangeProvider;
},
child: Consumer<DarkThemeProvider>(
builder: (BuildContext context, value, Widget child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: Styles.themeData(themeChangeProvider.darkTheme, context),
home: MyHomePage(),
);
},
),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
//bottom navbar items to build body
int _currentIndex = 1;
final List<Widget> _children = [
Search(),
CompaniesPage(),
Settings(),
];
@override
Widget build(BuildContext context) {
//checks web server status
checkSiteStatus(context);
Color themeColor = Theme.of(context).backgroundColor;
void changePage(int index){
setState(() {
_currentIndex = index;
});
}
//setting app name based on current page
String title = '';
if(_currentIndex == 0){
title = 'ابحث باستخدام التصنيفات';
}else if(_currentIndex == 1){
title = 'الشركات';
}else if(_currentIndex == 2){
title = 'الاعدادات';
}
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
bottomOpacity: 0.0,
elevation: 0.0,
title: new Center(
child: Text('$title',
style: TextStyle(color: Colors.white ,
fontSize: DeviceInformation(context).width * ResponsivenessController(context).responsiveFont
),
),
),
),
body: _children[_currentIndex],
bottomNavigationBar: CurvedNavigationBar(
index: _currentIndex,
color: themeColor,
backgroundColor: Colors.cyan,
height: 75.0,
items:<Widget>[
Icon(Icons.search, size: DeviceInformation(context).height * ResponsivenessController(context).responsiveNavIcons),
Icon(Icons.home, size: DeviceInformation(context).height * ResponsivenessController(context).responsiveNavIcons),
Icon(Icons.settings, size: DeviceInformation(context).height * ResponsivenessController(context).responsiveNavIcons),
],
onTap: changePage,
),
);
}
}
使用 MaterialApp 并为其设置标题。像这样:
import 'package:flutter/material.dart';
main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Your_App_Name',
home: DashboardPage(),
);
}
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Home sweet home"),
),
body: Home(),
);
你最好检查 appbar
你是否已经有一个标题。 title
可能也会从 main.dart
MaterialApp
是使用 Material 设计的 Flutter 应用程序的入口点,因此它应该只在 MyApp
小部件中声明一次。它的文档是 here.
如文档中所述,Material应用程序的 title 属性 是看到打开的应用程序时出现的那个。 AndroidManifest 中的 android:label
是显示在主屏幕上的标题。
您应该使用以下代码设置标题
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: Styles.themeData(themeChangeProvider.darkTheme, context),
home: MyHomePage(),
title: "EcoCat",
);