Use ThemeData as theme for CupertinoApp - ios

My app was built using a MaterialApp as the root widget. To this material app, I've added a theme as follows:
MaterialApp(
theme: myTheme,
home: MyHomePage(),
...
)
final ThemeData myTheme = _buildTheme();
ThemeData _buildTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
...
textTheme: _buildMyTextTheme(base.textTheme),
primaryTextTheme: _buildMyTextTheme(base.primaryTextTheme),
accentTextTheme: _buildMyTextTheme(base.accentTextTheme),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}));
}
TextTheme _buildMyTextTheme(TextTheme base) {
return base
.copyWith(
headline:
base.headline.copyWith(fontSize: 20.0, fontWeight: FontWeight.w500),
title: base.title.copyWith(fontSize: 18.0, fontWeight: FontWeight.w400),
subhead:
base.subhead.copyWith(fontSize: 16.0, fontWeight: FontWeight.w400),
body1: base.body1.copyWith(fontSize: 14.0, fontWeight: FontWeight.w400),
body2: base.body2.copyWith(fontSize: 14.0, fontWeight: FontWeight.w500),
caption: base.caption.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12.0,
),
)
.apply(
fontFamily: 'myfont',
displayColor: Colors.black,
bodyColor: Colors.black,
);
}
I've used Theme.of(context.textTheme to style the text in the whole app down the widget tree.
for example :
to a title I used
Text('Title', style:Theme.of(context).textTheme.title),
to a subtitle I used
Text('Title', style:Theme.of(context).textTheme.subhead),
It works as intended.
But now I want to use a CupertinoApp if the current platform is ios as it provides with native ios feel like
List item
Pages will be dismissible via a back swipe.
Scrolling past extremities will trigger iOS-style spring overscrolls.
How shall I add the CupertionApp applying the same text theming?

you can wrap the CupertinoApp with Theme widget:
Theme(
data: yourThemeData(), //your theme data here
child: CupertinoApp(...),
);

Related

how to resize text while click on text in flutter?

Here is my code
Container(
child: Positioned(
left: offset.dx,
top: offset.dy,
child: GestureDetector(
onPanUpdate: (details) {
setState(() {
offset = Offset(offset.dx + details.delta.dx, offset.dy + details.delta.dy);
print('offset $offset');
});
},
child: Text(_controller.text, textAlign: TextAlign.center, maxLines: 3,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0, color: colorrr)),),
),
)
The easiest way would be for you to put the fontSize in the State of your Widget, and update it from a button or tap somewhere.
Essentially, just like you update the offset, you can update a state variable named fontSize and use it in your TextStyle.
For resize text you may use
dependencies:
auto_size_text: ^3.0.0
import dart code:
import 'package:auto_size_text/auto_size_text.dart';
GestureDetector ontap inside use that code :
onTap: () {
child: AutoSizeText(
'This string will be automatically resized to fit in two lines.',
style: TextStyle(fontSize: 30),
maxLines: 2,
);
Hope you will get solution .
Also to know about package: https://pub.dev/packages/auto_size_text/install

How to change text color of Flutter license?

I'm new to Flutter. How do I change the text color of the Flutter license? Or if this is not possible, how do I override scaffoldBackgroundColor for a single screen?
I set my scaffoldBackgroundColor in my theme: ThemeData on the main.dart file to black.
But now my Flutter License can't be read because the text has defaulted to black.
I'm wondering if I can customize the text color in my flutter license or override my scaffoldBackgroundColor. I need a white scaffoldBackgroundColor in order for the Flutter license to display properly.
The only issue is if I change the scaffoldBackgroundColor in my main.dart page, it of course changes it for all my other screens which is not what i want. Many thanks for your help!
here is what my theme data looks like in main.dar
theme: ThemeData(
primaryColor: Color(0XFFeb1555),
accentColor: Color(0XFF5173A8),
scaffoldBackgroundColor: Color(0xff1D1E33),
canvasColor: Colors.black,
textTheme: TextTheme(
bodyText2: TextStyle(
color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.bold),
),
),
I edited three specific parts of the theme data in my main.dart file.
They were heading 5, bodyText2, and caption.
theme: ThemeData(
primaryColor: Color(0XFFeb1555),
accentColor: Color(0XFF5173A8),
scaffoldBackgroundColor: Color(0xff1D1E33),
canvasColor: Colors.black,
textTheme: TextTheme(
headline5: TextStyle(
color: Colors.white,
),
caption: TextStyle(
color: Colors.white,
),
bodyText2: TextStyle(
color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.bold),
),
),

How to wrap Text on AppBar

I added sub-Appbar on my application. How to view all text on the app bar without reducing font size?
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: submitRequestAppBar(context),
body: Scaffold(
appBar:
PreferredSize(
preferredSize: Size.fromHeight(40.0),
child:
AppBar(
backgroundColor: Colors.grey[350],
leading: Container(),
title: Text(
widget.title,
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 15.0),
),
),
),
You can create an scroll-animation to show the text that doesn't fit the screen. You can use this widget, the marquee. It's open-source so if you want to contribute you can just fork it and create a pull-request, from here.
It it's only wrapping you are after and don't care about the design. Then you should look into the solution on SO.

Cannot set fill color for OutlineButton [duplicate]

This question already has answers here:
How to set the background color of a Flutter OutlineButton?
(5 answers)
Closed 1 year ago.
The documentation for the OutlineButton says that the color property fills the button color and is transparent by default. Specifically the Flutter documentation says of the color property: "color → Color
The button's fill color, displayed by its Material, while it is in its default (unpressed, enabled) state."
But setting the color property has no effect:
OutlineButton(
color: Colors.orange,
textColor: BmsColors.primaryForegroundColor,
borderSide: BorderSide(color: BmsColors.primaryForegroundColor, width: 2.0),
shape: new RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(8.0),
),
child: Text(
this.text,
style: TextStyle(fontFamily: 'Lalezar', fontWeight: FontWeight.w400),
),
onPressed: () {},
);
If you check the source code of OutlineButton there is a method to get the fillColor
Color _getFillColor() {
if (widget.highlightElevation == null || widget.highlightElevation == 0.0)
return Colors.transparent;
final Color color = widget.color ?? Theme.of(context).canvasColor;
final Tween<Color> colorTween = ColorTween(
begin: color.withAlpha(0x00),
end: color.withAlpha(0xFF),
);
return colorTween.evaluate(_fillAnimation);
}
But this method has an if condition, it uses the color only when the highlightElevation is different from 0, and also it uses the animation of the colorTween from color.withAlpha(0x00) to color.withAlpha(0xFF).
So it change from transparent to your color when you press it.
You can create your own OutlineButton widget if you want , this a sample I made:
class MyCustomOutlineButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
final Color color;
const MyCustomOutlineButton({Key key, this.text, this.onPressed, this.color})
: super(key: key);
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.yellow, width: 2.0),
color: color,
borderRadius: BorderRadius.circular(8.0),
),
margin: EdgeInsets.all(2.0),
child: RawMaterialButton(
fillColor: color,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14.0),
child: Text(
text,
style: TextStyle(
fontFamily: 'Lalezar',
fontWeight: FontWeight.w400,
color: Colors.yellow),
),
),
onPressed: onPressed,
),
);
}
}
Usage
MyCustomOutlineButton(
text: "Become a Member",
color: Colors.orange,
onPressed: () {
print("here");
},
),
For what you want, you can use a simple RaisedButton combined with a RoundedRectangleBorder. See eg:
Container(
color: Colors.pink,
child: RaisedButton(
color: Colors.black,
child: Text('Become a member', style: TextStyle(color: Colors.yellow)),
onPressed: () {
print('Hello');
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(color: Colors.yellow, width: 5.0)),
),
)
The border color can be specified with the BorderSide, and the filled color is just the normal color property of RaisedButton.
Hope this help.

use flutter whats new package

i am trying to use the whats new package in my flutter application but I change th version and nothing happens, i implemmented it in the initstate of the class like this .Is it right??:
void initState() {
super.initState();
WhatsNewPage(
title: Text(
"What's New",
textScaleFactor: 1.0,
textAlign: TextAlign.center,
style: TextStyle(
// Text Style Needed to Look like iOS 11
fontSize: 22.0,
fontWeight: FontWeight.bold,
),
),
buttonText: Text(
'Continue',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
),
),
items: <ListTile>[
ListTile(
leading: Icon(Icons.color_lens),
title: Text(
'Dark Theme',
textScaleFactor: 1.0,
), //Title is the only Required Item
subtitle: Text(
'Black and grey theme (Tap to Change)',
textScaleFactor: 1.0,
),
onTap: () {
// You Can Navigate to Locations in the App
Navigator.of(context).pop();
},
),
], //Required
home: HomePage(),
showNow: false,
showOnVersionChange: true,
);}
Ok, it seems like the documentation is not clear, you can use that widget inside your build method, like my example below, replace NewPage() widget by the widget you want use after user press 'continue'
class TestingPackage extends StatefulWidget {
#override
TestingPackageState createState() => TestingPackageState();
}
class TestingPackageState extends State<TestingPackage> {
double textScaleFactor = 1.0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: WhatsNewPage(
title: Text(
"What's New",
textScaleFactor: textScaleFactor,
textAlign: TextAlign.center,
style: TextStyle(
// Text Style Needed to Look like iOS 11
fontSize: 22.0,
fontWeight: FontWeight.bold,
),
),
buttonText: Text(
'Continue',
textScaleFactor: textScaleFactor,
style: TextStyle(
color: Colors.white,
),
),
// Create a List of WhatsNewItem for use in the Whats New Page
// Create as many as you need, it will be scrollable
items: <ListTile>[
ListTile(
leading: Icon(Icons.color_lens),
title: Text(
'Dark Theme',
textScaleFactor: textScaleFactor,
), //Title is the only Required Item
subtitle: Text(
'Black and grey theme (Tap to Change)',
textScaleFactor: textScaleFactor,
),
onTap: () {
// You Can Navigate to Locations in the App
Navigator.of(context).pushNamed("/settings");
},
),
ListTile(
leading: Icon(Icons.map),
title: Text(
'Google Maps',
textScaleFactor: textScaleFactor,
),
subtitle: Text(
'Open Address Links in Google Maps instead of Apple Maps (Tap to Change)',
textScaleFactor: textScaleFactor,
),
onTap: () {
// You Can Navigate to Locations in the App
Navigator.of(context).pushNamed("/settings");
},
),
ListTile(
leading: Icon(Icons.person_outline),
title: Text(
'Loan Contacts Enhancements',
textScaleFactor: textScaleFactor,
),
subtitle: Text(
'Updated look for faster navigation',
textScaleFactor: textScaleFactor,
),
onTap: () {
WhatsNewPage.showDetailPopUp(
context,
'Info',
"Navigate to any loan then select the bottom right icon to go to the contacts. You can press the dropdown arrow for contact information.",
);
},
),
], //Required
home:
NewPage(), // Where the Button will Navigate (Usually the Login or Home Screen)
showNow:
false, // Show now regarless of version change (Useful for showing from the main menu)
showOnVersionChange:
true, //Show only if the version changes or the user reinstalls the app
),
);
}
}
class NewPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
child: Text("new page"),
),
);
}
}

Resources