Could you help me with this please.
Android studio is not indenting my code asfter i save all my project.
This is an example:
class DicePage extends StatelessWidget { #override Widget build(BuildContext context) { return Row( children: const [ Expanded(child: Image(image: AssetImage('images/dice1.png'),),), Expanded(child: Image(image: AssetImage('images/dice1.png'),),), ], ); } }
Related
I have a Text widget each time I change the size of the Text widget it keeps increasing in width and height, but i want to only Increase the Height of the Text widget.
I think you can make it by using the Transfrom widget.
Example
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(home: MyHomePage());
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Transform(
transform: Matrix4.identity()..scale(1.0, 1.5),
child: const Text(
'Transformed Text',
),
),
const SizedBox(height: 16.0),
const Text('Default Text'),
],
),
),
);
}
}
You can adjust in xml file to set height and width differently
I was trying to use fullscreen in my app, but I noticed that on devices with android 8.1 (API 27), when the user opens a keyboard the app exits fullscreen mode and doesn't comeback unless the ui is rebuild, does anyone have a solution?
I also tested on Android 7.1 (API 25) and the problem is easier to deal with, the only thing that doesn't come back to fullscreen is the top bar, but still, the code below only works flawless on new androids (API 28 +)
Code:
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([]);
return Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(flex: 1, child: Text('Fullscreen test')),
Flexible(
flex: 1,
child: TextFormField(
controller: TextEditingController(),
),
),
Flexible(flex: 1, child: SizedBox())
],
)),
);
}
}
You should call this in initState. Working code:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
void initState() {
// TODO: implement initState
super.initState();
SystemChrome.setEnabledSystemUIOverlays([]);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(flex: 1, child: Text('Fullscreen test')),
Flexible(
flex: 1,
child: TextFormField(
controller: TextEditingController(),
),
),
Flexible(flex: 1, child: SizedBox())
],
)),
);
}
}
I have a stateful widget which is conditionally rendering two childs inside stack, and i want to change the condition of the rending from a third child . any idea ?
Parent code :
class MapPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body:Body()
);
}
}
class Body extends StatefulWidget {
final String showScreen;
const Body({
Key key,
this.showScreen="post",
}) : super(key:key);
#override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
Widget _conditionedWidget(){
if(this.widget.showScreen=="map"){
return MapScreen();
}else if(this.widget.showScreen == "post"){
return PostScreen();
}
}
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
DrawerScreen(),
_conditionedWidget(),
],
);
}
}
child code
class DrawerScreen extends StatefulWidget {
#override
_DrawerScreenState createState() => _DrawerScreenState();
}
class _DrawerScreenState extends State<DrawerScreen> {
#override
Widget build(BuildContext context) {
return Container(
color:kPrimaryColor,
padding:EdgeInsets.only(top:70),
child:Column(
children: <Widget>[
Row(
children: <Widget>[
SizedBox(width:20.0),
CircleAvatar(),
SizedBox(width:10.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Biswas Sampad',style:TextStyle(
color:Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0,
)),
Text('#biswassampad',style:TextStyle(
color:Colors.grey[200],
fontSize: 15.0,
))
],
)
],
),
Container(
padding: EdgeInsets.symmetric(horizontal: 20,vertical:20),
margin: EdgeInsets.symmetric(vertical:30),
child: Column(
children: <Widget>[
MenuButton(icon:Icons.style, name:'Explore',action:(){
print('showing maop');
}),
MenuButton(icon:Icons.tag_faces, name:'Profile',action:(){
print('showing profile');
}),
MenuButton(icon:Icons.people, name:'People',action:(){
print('showing People');
}),
MenuButton(icon:Icons.speaker_notes, name:'Messages',action:(){
print('showing messages');
}),
MenuButton(icon:Icons.notifications, name:'Notifications',action:(){
print('showing Notifications');
}),
MenuButton(icon:Icons.satellite,name:'Settings',action:(){
print('showing settings');
})
],
),
),
LogoutSection()
],
)
);
}
}
So basically i want to change the showScreen value of the parent widget from DrawerScreen>MenuButton>action ?
any idea how to do it !! Thanks in advance.
You can use the Function in "DrawerScreen" widget like this :
write this code into the header of the class :
final Function onChangeState = Function();
DrawerScreen({#rquired onChangeState});
and in MenuButton call onChangeState function , like this:
MenuButton(icon:Icons.satellite,name:'Settings',action:(){
widget.onChangeState("Settings");
})
and change old code in Body widget to :
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
DrawerScreen(onChangeState : (newState){
setState(){
this.widget.showScreen = newState;
};
}),
_conditionedWidget(),
],
);
}
I need to be able to capitalize an entire textfield with writing in it when I click on a button, however when I kept searching the internet for a solution I couldn't find one, please help.
All you have to do is set the TextEditingController.text to its content, but with a call to .toUpperCase().
controller.text = controller.text.toUpperCase();
Here's an example app (which you can try on DartPad):
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
final _controller = TextEditingController();
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextField(
controller: _controller,
),
RaisedButton(
child: Text('toUpperCase()'),
onPressed: () {
_controller.text = _controller.text.toUpperCase();
},
),
],
);
}
}
can you help me figure whats wrong on my code?
import 'package:flutter/material.dart';
class test extends StatelessWidget {
#override
Widget texttest(String){
Text('hi');
}
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
texttest(String),
texttest('hello'),
texttest('wtf'),
],
)
);
}
}
can you help me figure what wrong? or am i missing something
Function TextTest should return a value, and some other errors have been fixed:
class Test extends StatelessWidget {
#override
Widget TextTest(String text) {
return Text(text);
}
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
TextTest('String'),
TextTest('hello'),
TextTest('wtf'),
],
));
}
}
update
Maybe what you want:
class Test extends StatelessWidget {
final String greeting;
Test(this.greeting);
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
Text(greeting),
Text('hello'),
Text('wtf'),
],
));
}
}
and use it Test('Hi')