超过百万的StackOverflow Flutter 问题

移动开发 作者: 2024-08-25 11:50:01
老孟导读:今天分享StackOverflow上高访问量的20大问题,这些问题给我一种特别熟悉的感觉,我想你一定或多或少的遇到过,有的问题在stackoverflow上有几十万的阅读量,说明很多人都遇到
Wrap(
  children: <Widget>[your_child])
Container(
        height: double.infinity,width: double.infinity,child:your_child)
Row(
  mainAxisSize: MainAxisSize.max,children: <Widget>[*your_child*],);
Column(
  mainAxisSize: MainAxisSize.max,children: <Widget>[your_child],);
@override
Widget build(BuildContext context) {
  return FutureBuilder(
    future: httpCall(),builder: (context,snapshot) {
     
    },);
}
class _ExampleState extends State<Example> {
  Future<int> future;

  @override
  void initState() {
    future = Future.value(42);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: future,snapshot) {
       
      },);
  }
}
Widget _currentBody;

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: _currentBody,bottomNavigationBar: BottomNavigationBar(
      items: <BottomNavigationBarItem>[
      	...
      ],onTap: (index) {
        _bottomNavigationChange(index);
      },),);
}

_bottomNavigationChange(int index) {
  switch (index) {
    case 0:
      _currentBody = OnePage();
      break;
    case 1:
      _currentBody = TwoPage();
      break;
    case 2:
      _currentBody = ThreePage();
      break;
  }
  setState(() {});
}
int _currIndex;

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: IndexedStack(
        index: _currIndex,children: <Widget>[OnePage(),TwoPage(),ThreePage()],);
}

_bottomNavigationChange(int index) {
  setState(() {
      _currIndex = index;
    });
}
TabBarView(
  controller: this._tabController,children: <Widget>[
    _buildTabView1(),_buildTabView2(),],)
var _newsKey = PageStorageKey('news');
var _technologyKey = PageStorageKey('technology');

TabBarView(
  controller: this._tabController,children: <Widget>[
    _buildTabView1(_newsKey),_buildTabView2(_technologyKey),)
Center(
  child: Container(
    height: 300,width: 300,color: Colors.blue,child: Stack(
      children: <Widget>[
        Positioned.fill(
          child: Container(
            height: 100,width: 100,color: Colors.red,)
      ],)
Positioned.fill(
  child: Align(
    child: Container(
      height: 100,)
class Test extends StatefulWidget {
  Test({this.data});
  final int data;
  @override
  State<StatefulWidget> createState() => _TestState();
}

class _TestState extends State<Test>{

}
  1. 在_TestState也定义同样的参数,此方式比较麻烦,不推荐。
  2. 直接使用widget.data(推荐)。
class BarrageItem extends StatefulWidget {
  BarrageItem(
      { this.text,this.duration = Duration(seconds: 3)});
const Duration _kDuration = Duration(seconds: 3);

class BarrageItem extends StatefulWidget {
  BarrageItem(
      {this.text,this.duration = _kDuration});
MaterialApp(
 debugShowCheckedModeBanner: false
)
Color(0xb74093)
Color(0xFFb74093)
class _FooState extends State<Foo> {
  TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = new TextEditingController(text: '初始值');
  }

  @override
  Widget build(BuildContext context) {
    return TextField(
          controller: _controller,);
  }
}
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('老孟'),body: Center(
        child: RaisedButton(
          color: Colors.pink,textColor: Colors.white,onPressed: _displaySnackBar(context),child: Text('show SnackBar'),);
  }
}

_displaySnackBar(BuildContext context) {
  final snackBar = SnackBar(content: Text('老孟'));
  Scaffold.of(context).showSnackBar(snackBar);
}
_scaffoldKey.currentState.showSnackBar(snackbar); 
Scaffold(
    appBar: AppBar(
        title: Text('老孟'),body: Builder(
        builder: (context) => 
            Center(
            child: RaisedButton(
            color: Colors.pink,onPressed: () => _displaySnackBar(context),child: Text('老孟'),);
killall -9 dart
taskkill /F /IM dart.exe
MediaQuery.of(context).size.width * 0.5
Row(
	children: <Widget>[
		Flexible(
			child: new TextField(),
FocusScope.of(context).requestFocus(_focusNode);
_focusNode = FocusNode();

TextField(
	focusNode: _focusNode,...
)
_focusNode.unfocus();
import 'dart:io' show Platform;

if (Platform.isAndroid) {
  // Android-specific code
} else if (Platform.isIOS) {
  // iOS-specific code
}
Platform.isAndroid
Platform.isFuchsia
Platform.isIOS
Platform.isLinux
Platform.isMacOS
Platform.isWindows
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config">
		 <!-- ... -->
    </application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	...
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
</dict>
</plist>
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_68377.html