Change application's starting dart file in flutter - 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()

Related

Flutter title doesn't change

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.

Provider Error: Could not find the correct Provider<Color> above this MyApp Widget

I do not understand why the following code generates the error?
According to me the provider is an ancestor to MaterialApp and it should work? What am I missing?
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
new Provider<Color>(create: (_) => Colors.amber)
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Provider.of<Color>(context),
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
)
);
}
}
Provider initially in build method. You don't access to use provider value because provider inits context, but you tried to use provider.of(context) in the same place. If you use another state(view), you should use it.
Example code : https://gist.github.com/VB10/358dc944e5a86b58db2d898eaa1b5ea6

Error when calling stream using streamprovider

I am trying to use stream provider in my app, but it is returning an error when I invoke 'stream', telling me that 'the named parameter stream is not defined'. is this not the correct way to call it?
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<FirebaseUser>.value(
stream: FirebaseAuth.instance.onAuthStateChanged),
],
child: MaterialApp(
title: 'Profile Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Profile'),
),
);
}
}
You likely changed from version 2 to 3.
The parameter got renamed:
StreamProvider.value(
value: myStream,
)
As the docs say, the property is called value, not stream
https://pub.dev/documentation/provider/latest/provider/StreamProvider/StreamProvider.value.html

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

How to implement a side-slide close page on the TargetPlatform.android?

Flutter setting TargetPlatform.iOS
new MaterialApp(
title: 'Mian',
theme: new ThemeData(
primarySwatch: Colors.orange,
platform: TargetPlatform.iOS,
)
)
Can skip the close page.
Flutter setting TargetPlatform.android
new MaterialApp(
title: 'Mian',
theme: new ThemeData(
primarySwatch: Colors.orange,
platform: TargetPlatform.android,
)
)
Can‘t skip the close page.
You can do it using CupertinoPageRoute when you push the Widget.
First you have to import cupertino:
import 'package:flutter/cupertino.dart';
Then use the Navigator:
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => YourNewWidgetPage()));
By reading the article I have new answers to update, this way is more friendly.
enter code 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,
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
})),
routes: {
"/": (BuildContext context) =>
MyHomePage(title: 'Flutter Demo Home Page'),
"/two": (BuildContext context) => TwoPage(),
},
);
}
}
Thanks to Arvinth for the article:https://medium.com/flutter-community/page-transitions-using-themedata-in-flutter-c24afadb0b5d