|
- import 'package:flutter/material.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
- import 'package:zhiying_comm_example/device_info_page.dart';
- import 'package:zhiying_comm_example/log_util.dart';
- import 'package:zhiying_comm_example/package_info_page.dart';
-
- void main() => runApp(MyApp());
-
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => _MyAppState();
- }
-
- class _MyAppState extends State<MyApp> {
- @override
- void initState() {
- super.initState();
- }
-
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: const Text('智莺-基础库'),
- ),
- body: HomePage(),
- ),
- );
- }
- }
-
- class HomePage extends StatelessWidget {
- netPost() async {
- dynamic result = await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
- print("result === ${result?.toString()}");
- }
-
-
- @override
- Widget build(BuildContext context) {
- return SingleChildScrollView(
- child: Center(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- RaisedButton(
- onPressed: () {
- Navigator.push(context, MaterialPageRoute(builder: (_) {
- return DeviceInfoPage();
- }));
- },
- child: Text('设备信息'),
- ),
- RaisedButton(
- onPressed: () {
- Navigator.push(context, MaterialPageRoute(builder: (_) {
- return PackageInfoPage();
- }));
- },
- child: Text('应用信息'),
- ),
- RaisedButton(
- onPressed: () {
- NetUtil.post('/siteapi/v1/ucenter/login/', params: {
- 'username': 'xiangguohui',
- 'password': 'fnuo123com'
- });
- },
- child: Text('登录请求'),
- ),
- RaisedButton(
- onPressed: () {
- NetUtil.request('/api/v1/rec/featured?page=1', params: null,
- onError: (msg) {
- print('onERROR = ${msg?.toString() ?? 'onError'}');
- }, onSuccess: (json) {
- print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
- }, onCache: (json) {
- print('onCache = ${json?.toString() ?? 'onCache'}');
- });
- },
- child: Text('网络异步请求(带缓存)'),
- ),
- RaisedButton(
- onPressed: () {
- netPost();
- },
- child: Text('网络同步请求(无缓存)'),
- ),
-
- RaisedButton(
- onPressed: (){
- LogUtil.test();
- },
- child: Text('显示日志'),
- ),
- RaisedButton(
- onPressed: (){
- Navigator.push(context, MaterialPageRoute(
- builder: (_){
- return Logger();
- }
- ));
- },
- child: Text('打开日志视图'),
- ),
-
- ],
- ),
- ),
- );
- }
- }
|