Is it possible o change the color or transparency of the drawer's scrim in flutter? Something like is Java's drawerLayout.setScrimColor(Color.TRANSPARENT);?
Thanks.
Flutter now includes a drawerScrimColor parameter in the Scaffold widget.
For example:
Scaffold(
drawerScrimColor: Colors.black,
);
Although I answered the question, #diegoveloper deserves the credit for submitting the PR
Following the same ideia brought by #diegoveloper and for that who might wonder how to make transparency just use the transparent color drawerScrimColor: Colors.transparent
https://api.flutter.dev/flutter/material/Colors/transparent-constant.html
You can change drawerTheme like this:
return ThemeData(
drawerTheme: DrawerThemeData(
scrimColor: Colors.transparent,
),
);
Related
Is it possible to change these icons color in IOS?
You can use SystemChrome
systemOverlayStyle: SystemUiOverlayStyle(
statusBarBrightness: Brightness.light, // For iOS: (dark icons)
statusBarIconBrightness: Brightness.dark, // For Android: (dark icons)
),
There are several ways to change the appearance of the status bar. If the application has an AppBar, you can set the backgroundColor and brightness arguments of the AppBar to change the style. If the application doesn't have an AppBar, you can use SystemChrome.setSystemUIOverlayStyle or AnnotatedRegion<SystemUiOverlayStyle>
I want to make android and IOS style.
I want to convert the code below into Cupertino, IOS style.
But I Can't Use Drawer Menu for IOS style. Why?
How can I use?
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(),
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
color: MyColors.blue,
),
),
centerTitle: true,
title: Text('Test', style: MyTextStyles.appBarTitle(deviceType) ),
actions: <Widget>[
Builder(
builder: (BuildContext context) => PlatformIconButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
icon: Icon(
Icons.menu,
)))])
body: .........
The Drawer widget is a Material-exclusive widget, and you can't use it directly on iOS.
You could build your own "Drawer-like" widget for iOS by replicating the build construction of a Drawer widget, but I would not recommend that, because drawers don't have that iOS "look and feel". As an iOS user myself, I know some very influential apps like Twitter have something that looks like a Drawer, but I think that is not the way a native iOS app would handle that kind of navigation.
What you can do instead, is having a Drawer widget for Android, and a bottom tab bar for iOS, which is a component that is way more common in iOS-styled apps. You can use the Platform class to check if your code is being executed on Android or iOS, and choose the right widget based on that.
Here is one example of such a build logic that you might find useful. I am very sorry I can't paste the code directly, I had this screenshot from a presentation I made and I don't remember where did I place the code for this project, but I hope you find it useful.
Is there a way to change the overlay background color when using showModalBottomSheet?
Right now the color is always a gray color, but I want to use a different color like green as shown below.
Here is the code used in the demo for reference
showModalBottomSheet<void>(context: context, builder: (BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text('This is the modal bottom sheet. Tap anywhere to dismiss.',
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 24.0
)
)
)
);
});
New Flutter UPDATE allows you to change the barrierColor in showModalBottomSheet()
showModalBottomSheet(
barrierColor: Colors.yellow.withOpacity(0.5),
You can actually change this but in order to do so you have to create a copy of this widget file in order to customize it. (steps below are for vscode)
However, by doing this, the widget won't be automatically updated by Flutter because it'd no longer be part of the SDK.
Create A Copy of A Widget To Customize
Right-click widget and select Go to definition - this will bring you to the widget's original file
Copy all of the code and paste it into a new .dart file with the same name - you'll notice there will now be errors due to a lack of dependencies.
In the case of BottomSheet you just need to add import 'package:flutter/material.dart';
Now import it like so import 'package:projectname/bottom_sheet.dart' as my; - the as my allows it to use the same .dart file name
Now when referencing it just add my. prior like so
my.showModalBottomSheet(
context: (context),
isScrollControlled: false,...
Customize Background Overlay Color
Now in bottom_sheet.dart just search for barrierColor and change Colors.black54 to whatever color you want!
I hope this will help anyone in the future!
Related Question
How to change the background color of BottomSheet in Flutter?
Short answer : you can't.
The color is hardcoded into the _ModalBottomSheetRoute class (as linked by #pskink) and there is no way to change its value.
I am trying to style a TextField in Flutter using the InputDecoration class.
Here is the implementation-
new TextField(
decoration: new InputDecoration(
border: InputBorder.none, // The named parameter border isn't defined
hintText: 'Please enter a search term'
),
);
But this results in a red squiggly line underneath border property with message
The parameter border isn't defined
Rest properties are working fine. Here is the screenshot of same -
PS - I'm new to Flutter.
You're on v0.0.22 of Flutter which is many months old. I found this PR from around the same time which says:
What was called the "divider" is now a configurable border
So my guess is that maybe the version you're using didn't have border.
You should switch to the beta channel (flutter channel beta) to try again with more recent code.
Go back feature works only on the edge of the screen on iPhone. How can I swipe to previous page from anywhere on the screen?
correct way is :
MaterialApp(
.
.
.
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}
)
),
.
.
.
);
Use CupertinoPageRoute to make it work on Android.
If I understood correctly the problem is how to set custom width of the iOS back swipe gesture area?
So one of the possible solutions is to use this package: cupertino_back_gesture.
Explanation from authors of package:
To change width of area where the user can start back swipe for the whole app:
Wrap your MaterialApp with BackGestureWidthTheme with desired backGestureWidth
set iOS builder of pageTransitionsTheme to CupertinoPageTransitionsBuilderCustomBackGestureWidth
import 'package:cupertino_back_gesture/cupertino_back_gesture.dart';
BackGestureWidthTheme( backGestureWidth: BackGestureWidth.fraction(1 / 2), child: MaterialApp(
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilderCustomBackGestureWidth(),
},
),
),
home: MainPage(),
),
)
Example app can be found on github.com
Another solution is to use swipeable_page_rout. It has specific parameter onlySwipeFromEdge: false.
In materialApp simply set in theme
theme: ThemeData(
primarySwatch: Colors.green,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
},
),
),
and where you are routing use CupertinoPageRoute instead of MaterialPageRoute it will work in right way .
You are most likely looking for PageView which allows swip to go next/previous page gesture.