Does anyone know why my navigation page isnt working after I click the icon Parking which will lead me to other pages which will display an appbar.
I can not test your code but I think this happens because you are trying to navigate between two different app roots. Try removing the MaterialApp widget from your "parkingscreen.dart" file. Keep only the Scaffold widget since it contains all material components for you to work. Let me know if it works!
Please have this kind of code in your ParkingScreen.dart file
class ParkingScreen extends StatelessWidget {
const ParkingScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Parking Screen')),
body: SafeArea(child: Column()),
);
}
}
This happens because you are trying to navigate between two different app roots
Related
I have a problem using Flutter Provider...
After Onbording screens I click to Next Button and needs to show me Welcome Screen (where i choose to log in with phone number)
But after clicking to Next Button i get this error - Could not find the correct Provider above this WelcomeScreen Widget
class _WelcomeScreenState extends State<WelcomeScreen> {
#override
Widget build(BuildContext context) {
final ap = Provider.of<AuthProvider>(context, listen: true);
return Scaffold(
body: SafeArea(
child: Center(
Make sure your Provider<> widget is present and at the root(like parent of MaterialApp for instance) to make sure it is in widget tree across rebuilds.
As far as I can see your code, you're calling Provider watch in welcome screen which prolly doesn't have the Provider in its tree. Move the watch to OnboardingScreen.
I am trying to create a Flutter page with reorder-able widgets of different sizes. The closest analogy is like Android/iOS home screens with widgets.
Both of these OS' can be have apps (1x1 size), small widgets (4x1), and even large widgets (4x4) on the same page. More so, when a large app takes up the full width of a page, it re-orders the widgets below/above it as to not interfere with the UI.
I am trying to do the same with Flutter, and hopefully make is so that user's can move widgets within my application the same way they do with their mobile operating systems.
The most similar StackOverFlow question to this one can be found here -- but its quite different.
Prerequisite packages:
reorderable_widgets.dart
custom_sizes.dart
The closest I got so far is with these two packages. But, I can't seem to figure the next steps after making this:
// imported packages
import 'package:flutter/material.dart';
import 'custom_sizes.dart';
import 'reorderable_widgets.dart';
class Demo extends StatelessWidget {
const Demo({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.grey,
body: CustomWidgetGrid(),
);
}
}
class CustomWidgetGrid extends StatefulWidget {
const CustomWidgetGrid({Key? key,}) : super(key: key);
#override
State<CustomWidgetGrid> createState() => _CustomWidgetGridState();
}
class _CustomWidgetGridState extends State<CustomWidgetGrid> {
final items1 = fillWithCustomWidgets1();
final items2 = fillWithCustomWidgets2();
final items3 = fillWithCustomWidgets2();
#override
Widget build(BuildContext context) {
return CustomScrollView(
clipBehavior: Clip.hardEdge,
slivers: <Widget>[
CustomSliverReorderableGrid(maxExtent: MediaQuery.of(context).size.width/(items2.length), children: items2,),
CustomSliverReorderableGrid(maxExtent: MediaQuery.of(context).size.width/items1.length, children: items1,),
],
);
}
}
This has already solved:
Having responsive, moveable widgets that save their end state
Providing padding around each widget
But the problem that I'm running at is that all widgets are the same size. Messing with the source code for the package has been a bit of pain, and I think that there is any easy solution that I missed (or don't know about).
Any thoughts would be greatly appreciated!
I'm working on a multi-page application, and currently have this:
void main() {
runApp(const MaterialApp(
title: "App", debugShowCheckedModeBanner: false, home: HomePage()));
}
And over in HomePage, I return a Material App
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(); //My home page
}
}
I looked online for if the home property of a MaterialApp should return another MaterialApp, as HomePage currently does, or if it should return a Scaffold, and I couldn't really find anything. I would think that a Scaffold makes a bit more sense, since that's what I would typically do in a single-page app, but the only thing that gives me pause is that in terms of syntax, making a new "MaterialApp" for each page and changing which is displayed sounds pretty nice-but I could very well be wrong.
Thanks!
A material app is used to define theme, route etc. So for the whole app it is good to have just one material app. Define all themes etc in it and have all other classes return a scaffold that way you have better control over the app..
More about material app
https://api.flutter.dev/flutter/material/MaterialApp-class.html
More about scaffold
https://api.flutter.dev/flutter/material/Scaffold-class.html
First of all, I don't recommend you to have two MaterialApp widgets, since you set properties in the first MaterialApp, meaning that the BuildContext of Flutter will not get those properties since there is a second MaterialApp widget lower in the widget tree.
What I would recommend you, is to directly pass your HomePage widget in the runApp function. That will allow you more clarity and visibility of your widgets:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "App", debugShowCheckedModeBanner: false, home: HomePage())
}
}
Then, in HomePage and all other pages that are views, you can return a Scaffold.
It's the 4th day of my Flutter. I used to use Unity.
Currently my project has 3 pages; Home, Profile, Settings
These pages are transitioned using Navigator.
The AppBar is declared in the Scaffold within each page, but the AppBar for all pages is the same.
So I have to write three of the same code. (always need to write and modify the same code as the number of pages increases in the future)
So I thought it looks good to declare AppBar as a variable and the page would just call it.
Like this:
//originappbar.dart
AppBar originAppBar(
backgroundColor: .....
)
//home.dart
class ShowHome extends StatelessWidget {
ShowHome({Key? key}) : super(key: key);
static const String route = '/home';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: originAppBar(), ....
//profile.dart
//Same as home.dart
In the above example, I'm trying to assign the originAppBar created by originappbar.dart to appbar: in home.dart or profile.dart.
But I can't declare AppBar as a variable.
I'm confused because I thought I could make AppBar a variable.
What's wrong with my code?
Thank you.
PreferredSizeWidget originAppBar = new AppBar(
backgroundColor: .....
)
//home.dart
class ShowHome extends StatelessWidget {
ShowHome({Key? key}) : super(key: key);
static const String route = '/home';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: originAppBar, ....
//profile.dart
//Same as home.dart
You can create a stateless widget like:
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget{
///Here goes your duplicated code
}
And just use that CustomAppBar everywhere.
Or create a widget CustomScaffold that is nothing more than the scaffold that you use in all your pages but with the CustomAppbar and any other hanges made.
I'm trying to replicate an Android app with Dart/Flutter that I already have a web version of written with PHP and Laravel. It has multiple sequentials screens that have the same components, like appbar, float button and a card to display contents of each screen. Using blade templates, is it possible to do something like:
<div class="card">
#yeld('card_content')
</div>
And use it in others views with:
#section('card_content')
<div class="table">
{{$data}}
</div>
#endsection
I know how to set a variable data in the constructor of the widget to be displayed, but how could I invoke a card widget and add children widgets to it, like in Laravel? Or should I copy the card code in every screen?
You have to define a new widget yourself and reuse the new widget whenever you need it. So just create a new Widget and return the card in the build function with the design you want to have it. For Example:
class MyPersonalCard extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Card(color: Colors.red, child: Text('This is a reusable card'),);
}
}
Now you could use MyPersonalCard() as widget like you would use your Card() widgets at the places you want them to be. You could also make the color still customizable if you do something like this:
class MyPersonalCard extends StatelessWidget {
final Color color;
const MyPersonalCard({Key key, this.color = Colors.red}) : super(key: key);
#override
Widget build(BuildContext context) {
return Card(color: this.color, child: Text('This is a reusable card'),);
}
}