基础库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

77 satır
1.9 KiB

  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // ignore_for_file: public_member_api_docs
  5. import 'dart:async';
  6. import 'package:flutter/material.dart';
  7. import 'package:package_info/package_info.dart';
  8. class PackageInfoPage extends StatelessWidget {
  9. @override
  10. Widget build(BuildContext context) {
  11. return MaterialApp(
  12. title: 'PackageInfo Demo',
  13. theme: ThemeData(primarySwatch: Colors.blue),
  14. home: MyHomePage(title: 'PackageInfo example app'),
  15. );
  16. }
  17. }
  18. class MyHomePage extends StatefulWidget {
  19. MyHomePage({Key key, this.title}) : super(key: key);
  20. final String title;
  21. @override
  22. _MyHomePageState createState() => _MyHomePageState();
  23. }
  24. class _MyHomePageState extends State<MyHomePage> {
  25. PackageInfo _packageInfo = PackageInfo(
  26. appName: 'Unknown',
  27. packageName: 'Unknown',
  28. version: 'Unknown',
  29. buildNumber: 'Unknown',
  30. );
  31. @override
  32. void initState() {
  33. super.initState();
  34. _initPackageInfo();
  35. }
  36. Future<void> _initPackageInfo() async {
  37. final PackageInfo info = await PackageInfo.fromPlatform();
  38. setState(() {
  39. _packageInfo = info;
  40. });
  41. }
  42. Widget _infoTile(String title, String subtitle) {
  43. return ListTile(
  44. title: Text(title),
  45. subtitle: Text(subtitle ?? 'Not set'),
  46. );
  47. }
  48. @override
  49. Widget build(BuildContext context) {
  50. return Scaffold(
  51. appBar: AppBar(
  52. title: Text(widget.title),
  53. ),
  54. body: Column(
  55. mainAxisAlignment: MainAxisAlignment.center,
  56. children: <Widget>[
  57. _infoTile('App name', _packageInfo.appName),
  58. _infoTile('Package name', _packageInfo.packageName),
  59. _infoTile('App version', _packageInfo.version),
  60. _infoTile('Build number', _packageInfo.buildNumber),
  61. ],
  62. ),
  63. );
  64. }
  65. }