how to extract all the relations between classes from a flutter file?
for example, in the below code, The desired output should be
1- I have widget RotationTransition
2- RotationTransition has one child of type Stack
3- Stack has children (Positioned, Center)
4- Positioned has a child of type FlutterLogo
5- Center has one child of type FlutterLogo
(It would be better if it's represented in tree form :D) any ideas How can I get such output?
RotationTransition(
turns: animation,
child: Stack(
children: [
Positioned.fill(
child: FlutterLogo(),
),
Center(
child: Text(
'Click me!',
style: TextStyle(
fontSize: 60.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
You can use Dart DevTools. It provides all the widget tree like below.
You can use dart tools if you are using VSCode
click on this icon to open dart
and than this will open
here all the widgets will be shown in tree form with there details too
Related
Update 2: created a new app with just the demo and it also doesn’t work on work computer except Firefox. Tried setting alerts throughout the index.html service_worker and they seem to trigger. The app that does work is older, so maybe something broken in the newer versions?
Update: I copied the working button into the non working one and it doesn’t work. So something about the entire web app doesn’t seem to work, not just the button.
Can someone suggest next steps to diagnose this issue? At home, everything works, so I'm assuming the issue lies in the workplace firewall (just a guess).
I'm using a simple TextButton, and on Firefox it works just fine (hover effect shows, and clicking does what it's supposed to).
However, in Chrome, Explorer, and Edge hovering over the button shows no hover effect, and clicking does nothing.
Unfortunately, the inspector is disabled at work, so I can't try and see what's going on, though that's limited anyway based on how Flutter draws out the app.
Interestingly (and perhaps helpfully), I have a second Flutter web app with a TextButton that does seem to work in all browsers at work. Here are the two buttons:
Working in all browsers:
TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.all(20)),
foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
overlayColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered))
return Colors.blue.withOpacity(0.8);
if (states.contains(MaterialState.focused) ||
states.contains(MaterialState.pressed))
return Colors.blue.withOpacity(0.12);
return null; // Defer to the widget's default.
},
),
),
child: new Text("Button Text", style: TextStyle(color: Colors.white)),
onPressed: () {
setState(() {
Navigator.pushNamed(context, '/route');
});
},
),
Working only in Firefox:
TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.all(20)),
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered))
return colorButtonTextHovered;
if (states.contains(MaterialState.focused) ||
states.contains(MaterialState.pressed))
return colorButtonTextFocusPress;
return colorButtonTextDefault;
},
),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered))
return colorButtonBackgroundHovered;
if (states.contains(MaterialState.focused) ||
states.contains(MaterialState.pressed))
return colorButtonBackgroundFocusPress;
return colorButtonBackgroundDefault;
},
),
),
child: new Text("Button Text"),
onPressed: () {
setState(() {
Navigator.push(
context,
FadeRoute(
MyApp.mtAppKey,
'/route',
),
);
});
},
),
Any tips, suggestions, next steps to diagnosing and fixing this issue?
I want to ask about the "Format Document" feature, why when using the "document format" feature in VScode, the tabulation becomes irregular like the code that I attached below.
I have tried to set "Editor: tab size" to 2 but when I use "Format Document", my code becomes irregular.
#override
Widget build(BuildContext context) {
````return new Container(
````````child: new Column(
``````children: <Widget>[
````````new Row(
``````````children: <Widget>[
````````````//slideshow
````````````new Expanded(
````````````````child: new CarouselSlider(
``````````````height: 150.0,
I expect the code like this :
#override
``Widget build(BuildContext context) {
````return new Container(
``````child: new Column(
````````children: <Widget>[
``````````new Row(
````````````children: <Widget>[
``````````````//slideshow
``````````````new Expanded(
````````````````child: new CarouselSlider(
````````````````height: 150.0,
The formatting is done by dart_style/dartfmt, and its convention is 2-space indenting, with 4 spaces for continued lines.
For Flutter code this often isn't the best formatting, so trailing commas can be used to change the formatting a little that works better:
https://flutter.dev/docs/development/tools/formatting#using-trailing-commas
(source: flutter.dev)
After poking around for solutions to this for months, thinking it must have something to do with the line length, the word wrapping, or other things, and none of it worked, I realized that if one has "Enable SDK Formatter" checked, it will seemingly override all of that with dart_style's choices.
Kind of sad to turn it off, as I'm sure it must be doing some other things that are useful. But I just can't live with that odd formatting that obfuscates the actual structure of the code as soon as I hit Save. So, if you're doing it manually in the settings.json, I would do:
"dart.enableSdkFormatter": false,
Android has PreferenceScreen which provides you the consistent Settings interface and handles a lot of SharedPreferences functionality on its own.
Is there anything similar in Flutter or do I have to create it by my own using custom ListView?
So, there doesn't exist any widget like that, you will have to create it on your own and handle their action in onChanged or onTap events. For example:
CheckBoxPreference
CheckboxListTile(
value: true,
title: Text("This is a CheckBoxPreference"),
onChanged: (value) {},
),
SwitchPreference
SwitchListTile(
value: false,
title: Text("This is a SwitchPreference"),
onChanged: (value) {},
),
ListPreference
ListTile(
title: Text("This is a ListPreference"),
subtitle: Text("Subtitle goes here"),
onTap: (){},
)
In Flutter the easiest way to make a PreferenceScreen page is with a ListView and ListTiles.
ListView(children: <Widget>[
ListTile(
title: Text('Enable Feature'),
trailing: Checkbox(
value: PrefService.getBool('feature_enabled'),
onChanged: (val) {
setState(() {
PrefService.setBool('feature_enabled', val);
});
},
),
onTap: () {
setState(() {
PrefService.setBool(
'feature_enabled', !PrefService.getBool('feature_enabled'));
});
},
)
]),
But you still need to listen for changes and save them.
To make that easier you can use the package preferences. It removes the boilerplate code and manages saving the changes. The example above would look like this with preferences:
PreferencePage([
CheckboxPreference(
'Enable Feature',
'feature_enabled',
)
]),
You can find it under https://pub.dartlang.org/packages/preferences.
For more features like subpages, hiding of preferences or more widgets look at the example.
According to my research now (I checked the https://pub.dartlang.org and other resources), the answer to your question is, no there is no page like that in Flutter (Check the official documentation). There is one plugin to have SharedPreferences which is from Flutter team, but if you check out its source code, you can see that it just does data modification. Other alternatives from other developers doesn't have anything visual too (I will keep checking, if I find one, I will edit my post).
There are some ways to do it, you can do it by calling android bridge and having android specific screen for only android (yeah I know, it doesn't make much sense) when you are with flutter or my real answer would be you can implement it by using list view as you mentioned and assign different child elements according to your needs.
Can i make a ExpansionPanel with header and body content from SQFLite database?
this is my code paste.ofcode.org/b8Mns5bSQxqyjX6BwD8DL8 I want to load the header and body from database
You are using ListView.builder to build the List. ListView.builder is meant for building UI widgets.
As it is not attached to the view (it's hanging in initState), ListView.builder will not have iterated once (you can put a print inside and see).
Solution is to use normal list
List.generate(data.length, (index) => new ItemKu(
false,
data[index]["category"],
new Container(
padding: new EdgeInsets.all(10.0),
child: new Text('Hello World'),
)
));
Ever since I updated Flutter for Android Studio, I have been getting this fatal crash everytime I try to run a hot reload:
Initializing hot reload...
I/flutter (20514): [INFO:engine.cc(582)] Could not configure asset bundle at path: /data/user/0/com.natech.flutterlaunch/cache/flutter_launchZTLJVC/flutter_launch/build/flutter_assets
D/MALI (20514): osup_destructor:170: osup_destructor
Lost connection to device.
After this error, my code changes do not bother reflecting on the app even when I run a full restart. Even if I remove all the widgets from the screen in hope it shows a blank space, the app remains the same. Here is my code:
class SplashScreen extends StatelessWidget{
#override
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(
image: splashBackgroundImage
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
width: 200.0,
height: 200.0,
alignment: Alignment.center,
decoration: new BoxDecoration(
image: logoImage
),
)
,/*new CircularProgressIndicator(
value: null,
strokeWidth: 1.0,
valueColor: new AlwaysStoppedAnimation<Color>(
Colors.blue
),
)*/
],
),
);
}
}
As you can see I commented out the CircularProgressIndicator but it still shows on the app even after a full restart. Anyone know what might be the issue?
This is very likely due to tracking the master branch, which has had a little instability in the last week or so around hot reloading and asset bundles.
You can try doing a flutter upgrade to see if the latest work in master will resolve your issues; it's more likely that you should be tracking beta (flutter channel beta) instead (or deal with hot reload not working until some more things are ironed out in master).