为什么我们需要在状态波动中的Statefulwidget中使用State方法?

时间:2019-02-08 02:16:44

标签: dart flutter

如果我们可以将所有代码放入'

,为什么需要'State'类

实际上,无状态窗口小部件无法实现内部数据的更改。因此,为此,我们使用有状态的小部件。 但是,为什么我们在有状态小部件中使用无状态小部件?

import 'package:flutter/material.dart';
void main()
{
  runApp(MyApp());
}

class MyApp extends StatefulWidget
{
  State<StatefulWidget>createState()
  {
    return _MyAppStore();
  }
}

class _MyAppStore extends State<MyApp>
{
  List<String> _products= ['food tester'];       
  build(context)
  {
    return MaterialApp(
      home: Scaffold(
        appBar:AppBar(
          title:Text("abe title hai yaar!!")
        ),
        body: Column(
          children:[
            Container(
              margin: EdgeInsets.all(10.00),
            child:RaisedButton(
              onPressed: () {},
              child:Text('VETO')
            ),
            ),
           Column(
             children: _products.map((element)=> Card(
               child:Column(
                 children: <Widget>[
                   Image.asset('assets/samantha.jpg'),
                   Text(element)
                 ],
               ),
               ))
               .toList(),
           ),
          ],
      ),
    )
    );
  }
}

tatefulwidget'?

0 个答案:

没有答案