博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
6_flutter_card(卡片),计算器,状态栏隐藏
阅读量:6474 次
发布时间:2019-06-23

本文共 6693 字,大约阅读时间需要 22 分钟。

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),      ),        ),        ),      );  }}复制代码

转载于:https://juejin.im/post/5c7cbffe518825730c7678fc

你可能感兴趣的文章
注释书写格式
查看>>
SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别
查看>>
2013=7=30 自增量的浅谈
查看>>
oracle11g dataguard 安装手册(转)
查看>>
java并发包分析之———Deque和LinkedBlockingDeque
查看>>
1. Two Sum - Easy - Leetcode解题报告
查看>>
SQLiteHelper
查看>>
多线程---同步函数的锁是this(转载)
查看>>
鱼C记事本V1.0(下)- 零基础入门学习Delphi28
查看>>
百练 2742 统计字符数 解题报告
查看>>
Ubuntu搜狗输入法候选词乱码
查看>>
js中回调函数写法
查看>>
React native android 最常见的10个问题
查看>>
数据结构和算法
查看>>
int a; int* a; int** a; int (*a)[]; int (*a)(int)
查看>>
.Net 项目代码风格要求
查看>>
java编码规范
查看>>
[pat]1045 Favorite Color Stripe
查看>>
Immutable学习及 React 中的实践
查看>>
【转】性能测试步骤
查看>>