1_card(卡片)
import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home:Scaffold( appBar: AppBar(title: Text('单行card'),),body: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ CardSaya(icon: Icons.home,teks: "HONE",warnaIcon: Colors.brown,), CardSaya(icon: Icons.favorite,teks: "favorite",warnaIcon: Colors.pink,), CardSaya(icon: Icons.place,teks: "place",warnaIcon: Colors.blue,), CardSaya(icon: Icons.settings,teks: "HONE",warnaIcon: Colors.black,), ], ),), ), ); }}class CardSaya extends StatelessWidget{ CardSaya({ this.icon,this.teks,this.warnaIcon}); final IconData icon; final String teks; final Color warnaIcon; @override Widget build(BuildContext context){ return Container(padding: EdgeInsets.all(10.0),child: Card( child: Column( children: [ Icon(icon,color: warnaIcon), Text(teks), ], ),), ); }}复制代码
2_计算器
import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(primarySwatch: Colors.red), home: HomePage(), ); }}class HomePage extends StatefulWidget { @override State createState() => HomePageState();}class HomePageState extends State { var num1 = 0, num2 = 0, sum = 0; final TextEditingController t1 = TextEditingController(text: "0"); final TextEditingController t2 = TextEditingController(text: "0"); void doAddition() { setState(() { num1 = int.parse(t1.text); num2 = int.parse(t2.text); sum = num1 + num2; }); } void doSub() { setState(() { num1 = int.parse(t1.text); num2 = int.parse(t2.text); sum = num1 - num2; }); } void doMul() { setState(() { num1 = int.parse(t1.text); num2 = int.parse(t2.text); sum = num1 * num2; }); } void doDiv() { setState(() { num1 = int.parse(t1.text); num2 = int.parse(t2.text); sum = num1 ~/ num2; }); } void doClear() { setState(() { t1.text = "0"; t2.text = "0"; }); } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomPadding: false, appBar: AppBar( title: Text("计算器"), ), body: SingleChildScrollView( padding: const EdgeInsets.all(40.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "输出: $sum", style: TextStyle( fontSize: 20.0, fontWeight: FontWeight.bold, color: Colors.purple), ), TextField( keyboardType: TextInputType.number, decoration: InputDecoration(hintText: "请输入"), controller: t1, ), TextField( keyboardType: TextInputType.number, decoration: InputDecoration(hintText: "请输入"), controller: t2, ), Padding( padding: const EdgeInsets.only(top: 20.0), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ MaterialButton( child: Text("+"), color: Colors.greenAccent, onPressed: doAddition, ), MaterialButton( child: Text("-"), color: Colors.greenAccent, onPressed: doSub, ), ], ), Padding( padding: const EdgeInsets.only(top: 20.0), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ MaterialButton( child: Text("*"), color: Colors.greenAccent, onPressed: doMul, ), MaterialButton( child: Text("/"), color: Colors.greenAccent, onPressed: doDiv, ), ], ), Padding( padding: const EdgeInsets.only(top: 20.0), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ MaterialButton( child: Text("清0"), color: Colors.greenAccent, onPressed: doClear, ), ], ) ], ), ), ); }}复制代码
3_状态栏隐藏
import 'package:flutter/material.dart';import 'package:flutter/services.dart';void main(){ SystemChrome.setEnabledSystemUIOverlays([]); runApp( MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('隐藏状态栏'), ), body: Center( child: Text('隐藏状态栏'), ), ), ); }}复制代码
3.1_隐藏状态栏不隐藏按键栏
import 'package:flutter/material.dart';import 'package:flutter/services.dart';void main(){ SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]); runApp( MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('隐藏状态栏不隐藏按键栏'), ), body: Center( child: Text('隐藏状态栏不隐藏按键栏'), ), ), ); }}复制代码
3.2_导航栏和状态栏颜色
import 'package:flutter/material.dart';import 'package:flutter/services.dart';void main(){ SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( systemNavigationBarColor: Colors.blue, statusBarColor: Colors.pink, )); runApp( MyApp());}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('Hello flutter'), ), body: Center( child: Text('Hello flutter'), ), ), ); }}复制代码
3.3_安全区
import 'package:flutter/material.dart';void main()=>runApp( MyApp());class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: SafeArea( child: SizedBox.expand( child: Card(color: Colors.yellowAccent), ), ), ), ); }}复制代码