Flutter: how to prevent device orientation changes and force portrait?

Import package:flutter/services.dart, then Put the SystemChrome.setPreferredOrientations inside the Widget build() method. Example: class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, ]); return new MaterialApp(…); } } Update This solution mightn’t work for some IOS devices as mentioned in the updated flutter documentation on Oct 2019. They Advise to fixed the … Read more

How to use conditional statement within child attribute of a Flutter Widget (Center Widget)

Actually you can use if/else and switch and any other statement inline in dart / flutter. Use an immediate anonymous function class StatmentExample extends StatelessWidget { Widget build(BuildContext context) { return Text((() { if(true){ return “tis true”;} return “anything but true”; })()); } } ie wrap your statements in a function (() { // your … Read more

Sizing elements to percentage of screen width/height

This is a supplemental answer showing the implementation of a couple of the solutions mentioned. FractionallySizedBox If you have a single widget you can use a FractionallySizedBox widget to specify a percentage of the available space to fill. Here the green Container is set to fill 70% of the available width and 30% of the … Read more

Dart SDK is not configured

I had the same problem after importing a flutter project from git. These are the steps to solve the problem. File->Settings->Language & Framework->Flutter Choose flutter SDK path: the first time we install flutter, we choose the location where the flutter should be installed. Choose this location. Click OK and the android studio will refresh. Carry … Read more

Scaffold.of() called with a context that does not contain a Scaffold

This exception happens because you are using the context of the widget that instantiated Scaffold. Not the context of a child of Scaffold. You can solve this by just using a different context : Scaffold( appBar: AppBar( title: Text(‘SnackBar Playground’), ), body: Builder( builder: (context) => Center( child: RaisedButton( color: Colors.pink, textColor: Colors.white, onPressed: () … Read more

How to create number input field in Flutter?

You can specify the number as keyboardType for the TextField using: keyboardType: TextInputType.number Check my main.dart file import ‘package:flutter/material.dart’; import ‘package:flutter/services.dart’; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new MaterialApp( home: new HomePage(), theme: new ThemeData(primarySwatch: Colors.blue), ); } } class HomePage … Read more

Message “flutter run: No connected devices”

Flutter supports both iOS and Android device/simulators. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device. Here is a reference document on how you can set up a device/simulator to run your application. For, Android (on a Mac system) Set up your Android device To prepare to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)