Flutter title doesn't change - flutter

I'm trying to change the title but despite the fact I changed the title it still shows the previous title on the tab of the browser.
void main() {
runApp(Myapp());
}
class Myapp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'New title ', : but still shows the old title on the browser
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
scaffoldBackgroundColor: Colors.black,
),
home: NavScreen(),
);
}
}

If you are changing the title during the run time, you just need to wrap it with the stateful Widget.
If your App title is static and does not change after a build, try clearing the flutter cache and rebuild your application again.

Related

How to use available browser fonts in a Flutter web app

I'd like to use fonts that are available in the browser, like all the standard font families. But specifying the font family isn't changing my fonts.
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter web app',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: TextTheme(bodyText2: TextStyle(fontFamily: 'Courier New'))
),
home: HomeView(),
);
}
}
How do I use available fonts without having to download and add the fonts to the project?
You can use Google font package
https://pub.dev/packages/google_fonts

trying to run flutter program and keep getting this error "the method 'HomeScreen' isn't defined for the type 'MyApp'

trying to run flutter program and keep getting this error "the method 'HomeScreen' isn't defined for the type 'MyApp' i need and answer to this problem quickly
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Food Delivery UI',
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.grey[50],
primaryColor: Colors.deepOrangeAccent,
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: HomeScreen(),
);
}
}
I think you miss import file of HomeScreen at top of the main.dart.
HomeScreen class wasn't define in main.dart file as per your code.
Or maybe class name is something else. Check it again.
Chances are Home Screen is in another .dart file. You'll need to import this dart file into your main.dart for it to work. Super easy fix just add this part at the top
import 'package:flutter/material.dart';
import 'package:<projectname>/lib/<subfolder if you have one>/HomeScreen.dart'
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Food Delivery UI',
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.grey[50],
primaryColor: Colors.deepOrangeAccent,
primarySwatch: Colors.blue,
),
home: HomeScreen(),
);
}
}

Change application's starting dart file in flutter

I am new for flutter and I want to change the starting UI(interface). I tried to find out . but could not do it
Here the home: parameter specifies the starting page. If you want to change the page that will open at startup, you can give the name of the page you want instead of HomePage ().
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Time Tracker',
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
),
);
}
}
So:
home: HomePage(),
Change to:
home: AnythingPage()

Change background color used in Recents apps screen with Flutter app

How can I change the color shown in the app switcher of Android. Right now the color comes up with a gray background, but I want it to be red.
This is the app code.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.red,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(
child: Text('Check color in app switcher.'),
),
);
}
}
The color parameter of MaterialApp has no effect.
If you are using the MaterialApp you would use the color attribute to change the color of the app bar in the switcher.
You could also use the SystemChrome.setApplicationSwitcherDescription method which you would find in package:flutter/services.dart

Recommended Dark/Light or custom Theme implementation in Flutter Cupertino

I’m currently implementing an iOS style app in flutter using the CupertinoApp class and Cupertino widgets. Now I would like to implement a different Theme for the application (like feedly did), so that the user can switch between both during runtime.
Unlike a MaterialApp, CupertinoApp has no property to set the theme.
MaterialApp with theme property:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
CupertinoApp without theme property:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
// theme: ThemeData(
// primarySwatch: Colors.blue,
// ),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
It looks like sb. is working on a CupertinoTheme which actually seems to be a Theme for a MaterialApp and not for a CupertinoApp.
What's the recommended way to define themes and change them during runtime in a Cupertino style app (e.g. Dark and Light Theme)?
First of all CupertinoThemeData is an alternative for ThemeData:
import 'package:flutter/cupertino.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
theme: CupertinoThemeData(),
home: MyHomePage(),
);
}
}
CupertinoThemeData has a 'raw' property which contains these properties:
Brightness, primaryColor, primaryContrastingColor, textTheme and so on.
Would you want to choose either dark or light? that's too easy!!
CupertinoThemeData.raw(Brightness.light)
CupertinoThemeData.raw(Brightness.dark)
but if you want to change it during runtime you should write a function:
CupertinoThemeData generalTheme(Brightness brightness) {
CupertinoThemeData _basicCupertinoTheme = CupertinoThemeData.raw(
brightness,
...
}
As you see, you can send an argument to function but don't forget to use setState method.
For more info check out CupertinoThemeData.raw constructor
you can use the following package to control dark and light themes, also the theme is saved directly into shared preferences so when you reopen the application, the latest theme you chose will be loaded,use the package as provided in the read me section.
https://pub.dartlang.org/packages/dynamic_theme