当前位置:   article > 正文

flutter10个常用的组件_flutter 星级组件

flutter 星级组件
  1. //基础格式。Text组件
  2. import 'package:flutter/material.dart';
  3. void main() {
  4. runApp(MyApp());
  5. }
  6. class MyApp extends StatelessWidget {
  7. @override
  8. Widget build(BuildContext context) {
  9. return MaterialApp(
  10. title: 'Text Widgetdddddd',
  11. home: Scaffold(
  12. body: Center(
  13. child: Text(
  14. 'Heldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgest',
  15. textAlign: TextAlign.center,
  16. maxLines: 1,
  17. overflow: TextOverflow.ellipsis,
  18. style: TextStyle(
  19. fontSize: 25.0, color: Color.fromARGB(255, 255, 127, 127)),
  20. ),
  21. ),
  22. ));
  23. }
  24. }
  1. import 'package:flutter/material.dart';
  2. void main() {
  3. runApp(MyApp());
  4. }
  5. class MyApp extends StatelessWidget {
  6. @override
  7. Widget build(BuildContext context) {
  8. return MaterialApp(
  9. title: 'Text Widgetdddddd',
  10. home: Scaffold(
  11. body: Center(
  12. child: Container(
  13. child: new Image.network(
  14. "https://blogimages.jspang.com/blogtouxiang1.jpg",
  15. fit: BoxFit.contain,
  16. repeat: ImageRepeat.repeat,
  17. ),
  18. width: 300.0,
  19. height: 200.0,
  20. color: Colors.blue,
  21. ),
  22. ),
  23. ));
  24. }
  25. }

列表组件

  1. import 'package:flutter/material.dart';
  2. void main() =>
  3. runApp(MyApp(items: new List<String>.generate(100, (i) => "Item $i")));
  4. class MyApp extends StatelessWidget {
  5. final List<String> items;
  6. MyApp({Key key, @required this.items}) : super(key: key);
  7. @override
  8. Widget build(BuildContext context) {
  9. return MaterialApp(
  10. title: 'ListView widget',
  11. home: Scaffold(
  12. body: new ListView.builder(
  13. itemCount: 100,
  14. itemBuilder: (context, index) {
  15. return new ListTile(
  16. title: new Text('${items[index]}'),
  17. );
  18. })),
  19. );
  20. }
  21. }

 

网格组件

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. return MaterialApp(
  7. title: 'ListView widget',
  8. home: Scaffold(
  9. appBar: new AppBar(title: new Text('网格组件')),
  10. body: new Container(
  11. child: new GridView(
  12. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  13. crossAxisCount: 3,
  14. childAspectRatio: 1,
  15. ),
  16. children: <Widget>[
  17. new Image.network(
  18. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  19. new Image.network(
  20. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  21. new Image.network(
  22. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  23. new Image.network(
  24. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  25. new Image.network(
  26. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  27. new Image.network(
  28. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  29. new Image.network(
  30. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  31. new Image.network(
  32. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  33. new Image.network(
  34. "https://blogimages.jspang.com/blogtouxiang1.jpg"),
  35. ],
  36. )),
  37. ),
  38. );
  39. }
  40. }

布局:5种

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. return MaterialApp(
  7. title: 'ListView widget',
  8. home: Scaffold(
  9. appBar: new AppBar(title: new Text('Row布局')),
  10. body: new Row(
  11. children: <Widget>[
  12. new RaisedButton(
  13. onPressed: () {},
  14. color: Colors.blue,
  15. child: new Text('Blue'),
  16. ),
  17. Expanded(
  18. child: new RaisedButton(
  19. onPressed: () {},
  20. color: Colors.orange,
  21. child: new Text('Blue'),
  22. )),
  23. new RaisedButton(
  24. onPressed: () {},
  25. color: Colors.blue,
  26. child: new Text('Blue'),
  27. )
  28. ],
  29. )),
  30. );
  31. }
  32. }
  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. return MaterialApp(
  7. title: 'ListView widget',
  8. home: Scaffold(
  9. appBar: new AppBar(title: new Text('Colum布局')),
  10. body: new Column(
  11. crossAxisAlignment: CrossAxisAlignment.start,
  12. mainAxisAlignment: MainAxisAlignment.center,
  13. children: <Widget>[
  14. Center(child: Text('I am JSPang')),
  15. Expanded(child: Text('my website is jspang.com')),
  16. Center(child: Text('I love coding'))
  17. ],
  18. )),
  19. );
  20. }
  21. }
  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. var stack = new Stack(
  7. alignment: const FractionalOffset(0.5, 0.8),
  8. children: <Widget>[
  9. new CircleAvatar(
  10. backgroundImage: new NetworkImage(
  11. 'https://blogimages.jspang.com/blogtouxiang1.jpg'),
  12. radius: 100.0,
  13. ),
  14. new Container(
  15. decoration: new BoxDecoration(
  16. color: Colors.lightBlue,
  17. ),
  18. padding: EdgeInsets.all(5.0),
  19. child: new Text('JSPang 技术胖'),
  20. ),
  21. new Positioned(
  22. top: 10.0,
  23. left: 10.0,
  24. child: new Text('JSPang.com'),
  25. ),
  26. new Positioned(
  27. bottom: 10.0,
  28. right: 10.0,
  29. child: new Text('技术胖'),
  30. )
  31. ],
  32. );
  33. return MaterialApp(
  34. title: 'ListView widget',
  35. home: Scaffold(
  36. appBar: new AppBar(
  37. title: new Text('垂直方向布局'),
  38. ),
  39. body: Center(child: stack),
  40. ),
  41. );
  42. }
  43. }
  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. var card = new Card(
  7. child: Column(
  8. children: <Widget>[
  9. ListTile(
  10. title: new Text(
  11. '吉林省吉林市昌邑区',
  12. style: TextStyle(fontWeight: FontWeight.w500),
  13. ),
  14. subtitle: new Text('技术胖:1513938888'),
  15. leading: new Icon(
  16. Icons.account_box,
  17. color: Colors.lightBlue,
  18. ),
  19. ),
  20. new Divider(),
  21. ListTile(
  22. title: new Text(
  23. '北京市海淀区中国科技大学',
  24. style: TextStyle(fontWeight: FontWeight.w500),
  25. ),
  26. subtitle: new Text('胜宏宇:1513938888'),
  27. leading: new Icon(
  28. Icons.account_box,
  29. color: Colors.lightBlue,
  30. ),
  31. ),
  32. new Divider(),
  33. ListTile(
  34. title: new Text(
  35. '河南省濮阳市百姓办公楼',
  36. style: TextStyle(fontWeight: FontWeight.w500),
  37. ),
  38. subtitle: new Text('JSPang:1513938888'),
  39. leading: new Icon(
  40. Icons.account_box,
  41. color: Colors.lightBlue,
  42. ),
  43. ),
  44. new Divider(),
  45. ],
  46. ),
  47. );
  48. return MaterialApp(
  49. title: 'ListView widget',
  50. home: Scaffold(
  51. appBar: new AppBar(
  52. title: new Text('卡片布局'),
  53. ),
  54. body: Center(child: card),
  55. ),
  56. );
  57. }
  58. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/289716?site
推荐阅读
相关标签
  

闽ICP备14008679号