main.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /// ignore_for_file: public_member_api_docs
  2. import 'dart:ui';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/rendering.dart';
  5. import 'package:flutter_svg/avd.dart';
  6. import 'package:flutter_svg/flutter_svg.dart';
  7. /// Assets that will be rendered.
  8. const List<String> assetNames = <String>[
  9. // 'assets/notfound.svg', // uncomment to test an asset that doesn't exist.
  10. 'assets/flutter_logo.svg',
  11. 'assets/dart.svg',
  12. 'assets/simple/clip_path_3.svg',
  13. 'assets/simple/clip_path_2.svg',
  14. 'assets/simple/clip_path.svg',
  15. 'assets/simple/fill-rule-inherit.svg',
  16. 'assets/simple/group_fill_opacity.svg',
  17. 'assets/simple/group_opacity.svg',
  18. 'assets/simple/text.svg',
  19. 'assets/simple/text_2.svg',
  20. 'assets/simple/linear_gradient.svg',
  21. 'assets/simple/linear_gradient_2.svg',
  22. 'assets/simple/male.svg',
  23. 'assets/simple/radial_gradient.svg',
  24. 'assets/simple/rect_rrect.svg',
  25. 'assets/simple/rect_rrect_no_ry.svg',
  26. 'assets/simple/style_attr.svg',
  27. 'assets/w3samples/aa.svg',
  28. 'assets/w3samples/alphachannel.svg',
  29. 'assets/simple/ellipse.svg',
  30. 'assets/simple/dash_path.svg',
  31. 'assets/simple/nested_group.svg',
  32. 'assets/simple/stroke_inherit_circles.svg',
  33. 'assets/simple/use_circles.svg',
  34. 'assets/simple/use_opacity_grid.svg',
  35. 'assets/wikimedia/chess_knight.svg',
  36. 'assets/wikimedia/Ghostscript_Tiger.svg',
  37. 'assets/wikimedia/Firefox_Logo_2017.svg',
  38. ];
  39. /// Assets treated as "icons" - using a color filter to render differently.
  40. const List<String> iconNames = <String>[
  41. 'assets/deborah_ufw/new-action-expander.svg',
  42. 'assets/deborah_ufw/new-camera.svg',
  43. 'assets/deborah_ufw/new-gif-button.svg',
  44. 'assets/deborah_ufw/new-gif.svg',
  45. 'assets/deborah_ufw/new-image.svg',
  46. 'assets/deborah_ufw/new-mention.svg',
  47. 'assets/deborah_ufw/new-pause-button.svg',
  48. 'assets/deborah_ufw/new-play-button.svg',
  49. 'assets/deborah_ufw/new-send-circle.svg',
  50. 'assets/deborah_ufw/numeric_25.svg',
  51. ];
  52. /// Assets to test network access.
  53. const List<String> uriNames = <String>[
  54. 'http://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg',
  55. 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg',
  56. 'https://upload.wikimedia.org/wikipedia/commons/b/b4/Chess_ndd45.svg',
  57. ];
  58. void main() {
  59. runApp(MyApp());
  60. }
  61. class MyApp extends StatelessWidget {
  62. @override
  63. Widget build(BuildContext context) {
  64. return MaterialApp(
  65. title: 'Flutter Demo',
  66. theme: ThemeData(
  67. primarySwatch: Colors.blue,
  68. ),
  69. home: const MyHomePage(title: 'Flutter SVG Demo'),
  70. );
  71. }
  72. }
  73. class MyHomePage extends StatefulWidget {
  74. const MyHomePage({Key key, this.title}) : super(key: key);
  75. final String title;
  76. @override
  77. _MyHomePageState createState() => _MyHomePageState();
  78. }
  79. class _MyHomePageState extends State<MyHomePage> {
  80. final List<Widget> _painters = <Widget>[];
  81. double _dimension;
  82. @override
  83. void initState() {
  84. super.initState();
  85. _dimension = 203.0;
  86. for (String assetName in assetNames) {
  87. _painters.add(
  88. SvgPicture.asset(assetName),
  89. );
  90. }
  91. for (int i = 0; i < iconNames.length; i++) {
  92. _painters.add(
  93. Directionality(
  94. textDirection: TextDirection.ltr,
  95. child: SvgPicture.asset(
  96. iconNames[i],
  97. color: Colors.blueGrey[(i + 1) * 100],
  98. matchTextDirection: true,
  99. ),
  100. ),
  101. );
  102. }
  103. for (String uriName in uriNames) {
  104. _painters.add(
  105. SvgPicture.network(
  106. uriName,
  107. placeholderBuilder: (BuildContext context) => Container(
  108. padding: const EdgeInsets.all(30.0),
  109. child: const CircularProgressIndicator()),
  110. ),
  111. );
  112. }
  113. // Shows an example of an SVG image that will fetch a raster image from a URL.
  114. _painters.add(SvgPicture.string('''<svg viewBox="0 0 200 200"
  115. xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  116. <image xlink:href="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" height="200" width="200"/>
  117. </svg>'''));
  118. _painters.add(AvdPicture.asset('assets/android_vd/battery_charging.xml'));
  119. }
  120. @override
  121. Widget build(BuildContext context) {
  122. if (_dimension > MediaQuery.of(context).size.width - 10.0) {
  123. _dimension = MediaQuery.of(context).size.width - 10.0;
  124. }
  125. return Scaffold(
  126. appBar: AppBar(
  127. title: Text(widget.title),
  128. ),
  129. body: Column(children: <Widget>[
  130. Slider(
  131. min: 5.0,
  132. max: MediaQuery.of(context).size.width - 10.0,
  133. value: _dimension,
  134. onChanged: (double val) {
  135. setState(() => _dimension = val);
  136. }),
  137. Expanded(
  138. child: GridView.extent(
  139. shrinkWrap: true,
  140. maxCrossAxisExtent: _dimension,
  141. padding: const EdgeInsets.all(4.0),
  142. mainAxisSpacing: 4.0,
  143. crossAxisSpacing: 4.0,
  144. children: _painters.toList(),
  145. ),
  146. ),
  147. ]),
  148. );
  149. }
  150. }