一、目标:使用StreamBuilder模拟实现每隔一秒返回从网络中获取的数据,并刷新页面。 效果图: Stream.periodic构造,顾名思义,是用来创建流,在周期间隔反复广播事件。 <code>import 'package:flutter/material.dart'; main()=>runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({Key? k…
一、目标:使用StreamBuilder模拟实现每隔一秒返回从网络中获取的数据,并刷新页面。 效果图: Stream.periodic构造,顾名思义,是用来创建流,在周期间隔反复广播事件。 <code>import 'package:flutter/material.dart'; main()=>runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({Key? k…
效果图:Form表单校验 <code>import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialA…
效果图: 1、获取文本 <code>import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialAp…
效果图: <code>import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debu…
1、async...await 返回的是Future,后面可以接then() <code>import 'package:flutter/material.dart'; main(){ renderSome(); } request() async{ await Future.delayed(const Duration(seconds: 2)); return "response"; } doSomething() async{ …
例子效果图: 代码: <code>import 'dart:math'; import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(Buil…
例子1: SliverGridDelegateWithMaxCrossAxisExtent 效果图: <code>import 'dart:math'; import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : supe…
NetworkImage 例子: 先上效果图: <code>import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { retur…
例子一: 先上图: <code>import 'package:flutter/material.dart'; main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const Mater…
先上图: <code>import 'package:flutter/material.dart'; main(){ runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const MaterialApp…