I'm trying to use a drawer with PlatformScaffold but it seems MaterialAppBarData does not have a named parameter for drawer. What is the workflow for adding a drawer using flutter platform widgets for the newer versions. For example in ^0.72.0. I can't seem to find any information on this in the docs or on forums.
Found a tutorial using the PlatformAppBar and saw that I should use the material argument in the scaffold other than the one in the PlatformAppBar. Closing this. Below is the workflow.
PlatformApp(
home: PlatformScaffold(
appBar: PlatformAppBar(
title: Text("Title"),
),
body: AppContent(),
material: (context, platform) => MaterialScaffoldData(drawer: Drawer()),
),
);
Related
I know I should not disable any of the text and bold settings set on the device but I have a reason for it. I have disabled the text size by setting the textScaleFactor to 1 on a global level. But this does nothing to avoid the user from setting the Bold Text option that also changes the size of the text. How do I override that function also so even if the user sets it on the device there is no effect on the app? I have tried setting the fontweitgh on the text item using a TextStyle but that does also not stop the Bolding.
After checking Text widget I found out that it's using boldTextOverride from MediaQuery to change font weight of default text style provided to it. So I guess you can override it by wrapping your MeterialApp inside of a MediaQuery and assigning false to boldText and set useInheritedMediaQuery on MaterialApp to true to prevent it from creating another MediaQuery. Something like this:
return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: false),
child: MaterialApp(
useInheritedMediaQuery: true,
),
);
Amir_P's answer is good but, when testing it out, I found that it breaks switching between dark mode and light mode in system, as the Flutter app would only apply system brightness after killing and reopening the app on iOS rather than immediately while the app is open. Therefore, I think that rather than wrapping MaterialApp in a MediaQuery, the following should be done:
return MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(boldText: false),
child: child!,
),
);
The builder property of the Material App is specifically for overriding things like this - see https://api.flutter.dev/flutter/material/MaterialApp/builder.html
Are there any code examples out there that show how to use an Overlay independant of a Navigator widget?
In our app, we do not want the TitleBar/AppBar to be part of the main nav-stack, it should stay at the top of the window, and be fixed position.
The TitleBar needs acccess to an Overlay though, as it has various tool-tips and pop-up panels.
The only I know to do this is double-wrap Navigator, or MaterialApp, both of which smell bad. I would like to use Overlay directly, but lack any guidance on how to implement it.
Looking a the source of Overlay does not provide much help, and I'd prefer not to delve too deeply into MaterialApp's thousands of lines of src code.
[EDIT] Looking at the Navigator source a bit, it seems Overlay is directly coupled to PageRoutes, which is a real shame :'( It would be nice if there was a simple Overlay(child: ) we could just use.
There is declarative package for using overlays called flutter_portal which lets you show overlays as part of the widget tree.
PortalEntry(
visible: true,
portal: Material(
elevation: 8,
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(title: Text('option 1')),
ListTile(title: Text('option 2')),
],
),
),
),
child: RaisedButton(...),
)
With this setup, you can toggle the overlay on and off with a single boolean ('visible') and you no longer have to make calls to Overlay.insert and Overlay.remove.
I want to launch a simple walk-through for our app. The user would log in for the first time (or select the 'tutorial' option in settings), and it would walk you through how to use the app.
To clarify, the app would launch a dialog/alertdialog and the background would go grey or become greyed out highlighting specific areas/buttons of the app to talk them through it. The dialog box would have a child of Text explaining how to use it.
After the user has clicked through the steps the tutorial would end but could be reactivated in settings.
Any help would be appreciated.
Thanks
There is a plugin called showcaseview and does pretty much what you want. You can get it here. For using it you need to wrap the page you want to show in a ShowCaseWidget
ShowCaseWidget(
builder: Builder(
builder : (context) () => Somewidget()
),
),
then for every part of the page you want to show a guide for it, wrap it in a ShowCase
Showcase(
key: _one,
title: 'Menu',
description: 'Click here to see menu options',
child: Icon(
Icons.menu,
color: Colors.black45,
),
),
I would like to use both device_preview and auto_route. To do so, I need to add the respective codes to the builder property of MaterialApp. However, since there is only one builder property in MaterialApp widget, I can only use one of the packages. What can I do to use both?
The builder property in Material App will give you context and a Native navigator in case you want to wrap it with some theme data or something, so instead of passing the native navigator pass your ExtendedNavigator.
MaterialApp(
builder: (context, nativeNavigator) => DevicePreview.appBuilder(
context,
ExtendedNavigator(router: Router()),
),
If anyone is using auto_route in version 0.6.2 or above, you might be struggling with the solution, as the answer above doesn't work anymore, since auto_route is using ExtendedNavigator.builder now. This is how you can solve the issue:
MaterialApp(
locale: DevicePreview.of(context).locale,
builder: (context, nativeNavigator) => DevicePreview.appBuilder(
context,
ExtendedNavigator.builder<Router>(
router: Router(),
)(context, nativeNavigator),
),
);
I currently have a Flutter app which keeps track of the amount of time a user spends on the app with a timer which runs in the background. Users can set limits on the amount of time they spend in the app. Every minute, the timers checks if the user has exceeded their time limit. If so, I want to display a dialog or alert telling the user this.
The problem is that the timer has no way to access the current context and thus no way to create my dialog. Is there a way to get around this?
There is a package that enables you show dialogs with no need BuildContext from business layer. It's called OneContext.
That package also works with page navigation, overlays and other things with no need BuildContext.
Take a look at: https://pub.dev/packages/one_context
Use example:
// example dialog
OneContext().showDialog(
// barrierDismissible: false,
builder: (_) => AlertDialog(
title: new Text("The Title"),
content: new Text("The Body"),
)
);
// example snackBar
OneContext().showSnackBar(
builder: (_) => SnackBar(content: Text('My awesome snackBar!'))
);
You can achieve that by creating a custom Dialog Manager and a locator.
You can read the full tutorial here : https://medium.com/flutter-community/manager-your-flutter-dialogs-with-a-dialog-manager-1e862529523a
There is a package for it called Stacked_services
It provides: NavigationService, DialogService and SnackbarService.