超过百万的StackOverflow Flutter 问题-第二期

移动开发 作者: 2024-08-24 22:55:01
老孟导读:一个月前分享的《超过百万的StackOverflow Flutter 问题 第一期》受到很多朋友的喜欢,非常感谢大家的支持,在文章末尾有第一期的链接,希望此文能对你有所帮助。 No conn
  1. Doctor summary (to see all details,run flutter doctor -v):
    [✓] Flutter (Channel stable,v1.12.13+hotfix.9,on Mac OS X 10.14.6 18G1012,locale zh-Hans-CN)
     
    [!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        ! Some Android licenses not accepted.  To resolve this,run: flutter doctor
          --android-licenses
    [✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    [✓] Android Studio (version 3.5)
    [✓] Connected device (1 available)
    
    ! Doctor found issues in 1 category.
    
Scaffold.of(context).showSnackBar(SnackBar(
      content: Text("Sending Message"),));
Fluttertoast.showToast(
        msg: "This is Toast messaget",toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER,timeInSecForIos: 1
    );
  1. shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(18.0),side: BorderSide(color: Colors.red)
    ),
  2. ClipRRect(
      borderRadius: BorderRadius.circular(40),child: RaisedButton(
        onPressed: () {},child: Text("Button"),),)
    
  3. ButtonTheme(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),)
    
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <!-- <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item> -->
</layer-list>

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/splash" />
    </item>
</layer-list>

defaultConfig {
    applicationId "com.example.fluttersample"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
new Container(
  margin: const EdgeInsets.all(15.0),padding: const EdgeInsets.all(3.0),decoration: BoxDecoration(
    border: Border.all(color: Colors.blueAccent)
  ),child: Text("My Awesome Border"),)
SizedBox.expand(
  child: RaisedButton(...),)
SizedBox(
  width: double.infinity,// height: double.infinity,child: RaisedButton(...),)
ConstrainedBox(
    constraints: const BoxConstraints(minWidth: double.infinity),)
ButtonTheme(
  minWidth: double.infinity,child: MaterialButton(
    onPressed: () {},child: Text('Raised Button'),
Column(
  children: <Widget>[
    Container(
      height: 50,child: ListView(),)
  ],)
Column(
  children: <Widget>[
     Expanded(
      child: horizontalList,);
ClipRRect(
    borderRadius: BorderRadius.circular(8.0),child: Image.network(
        '',)
CircleAvatar(
  radius: 20,backgroundImage: NetworkImage('https://via.placeholder.com/140x100')
)
ClipOval(
  child: Image.network(
    "image_url",height: 100,width: 100,fit: BoxFit.cover,
Container(
        width: 100.0,height: 150.0,decoration: BoxDecoration(
          image: DecorationImage(
                fit: BoxFit.cover,image: NetworkImage('Path to your image')
              ),borderRadius: BorderRadius.all(Radius.circular(8.0)),color: Colors.redAccent,
InputDecoration(
    border: InputBorder.none,hintText: 'Username',
class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,DeviceOrientation.portraitDown,]);
      return new MaterialApp(...);
    }
  }
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>
Opacity(
  opacity: .0,child:,)
Visibility(
  visible: false,)
Offstage(
  offstage: true,)
@override
Widget build(BuildContext context) {
  return new WillPopScope(
    onWillPop: () async => false,child: new Scaffold(
      appBar: new AppBar(
        title: new Text("data"),leading: new IconButton(
          icon: new Icon(Icons.ac_unit),onPressed: () => Navigator.of(context).pop(),);
}
ButtonTheme(
  minWidth: 200.0,height: 100.0,child: Text("test"),);
SizedBox(
  width: 100,// specific value
  child: RaisedButton(...)
)
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example',home: Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(50.0),// here the desired height
          child: AppBar(
            // ...
          )
        ),body: // ...
      )
    );
  }
}
import 'package:intl/intl.dart';

DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
Widget getTextWidgets(List<String> strings)
  {
    List<Widget> list = new List<Widget>();
    for(var i = 0; i < strings.length; i++){
        list.add(new Text(strings[i]));
    }
    return new Row(children: list);
  }
Row(children: strings.map((item) => new Text(item)).toList())
var list = ["one","two","three","four"]; 

child: Column(
          mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
             for(var item in list ) Text(item)
          ],
class MyHomePage extends StatefulWidget {
  MyHomePage({Key key,this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<String> widgetList = ['A','B','C'];

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;

    /*24 is for notification bar on Android*/
    final double itemHeight = (size.height - kToolbarHeight - 24) / 2;
    final double itemWidth = size.width / 2;

    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),body: new Container(
        child: new GridView.count(
          crossAxisCount: 2,childAspectRatio: (itemWidth / itemHeight),controller: new ScrollController(keepScrollOffset: false),shrinkWrap: true,scrollDirection: Axis.vertical,children: widgetList.map((String value) {
            return new Container(
              color: Colors.green,margin: new EdgeInsets.all(1.0),child: new Center(
                child: new Text(
                  value,style: new TextStyle(
                    fontSize: 50.0,color: Colors.white,);
          }).toList(),);
  }
}
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    return MaterialApp(
      title: app_title,theme: ThemeData(
        primarySwatch: Colors.blue,home: HomePage(title: home_title),);
  }
}
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.white
));
return Column(
  crossAxisAlignment: CrossAxisAlignment.center,mainAxisSize: MainAxisSize.max,mainAxisAlignment: MainAxisAlignment.end,children: <Widget>[
      //your elements here
  ],);
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_68067.html