From 036c71f7ee0a55069c515e8af9f9da5f7c293d9b Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sat, 21 Apr 2018 00:59:26 +0800 Subject: [PATCH] Add iOS version UI --- lib/android/main.android.dart | 107 +++++++++++++++++++++++++++++++++ lib/ios/home.dart | 44 ++++++++++++++ lib/ios/main.dart | 86 ++++++++++++++++++++++++++ lib/main.dart | 110 +--------------------------------- 4 files changed, 240 insertions(+), 107 deletions(-) create mode 100644 lib/android/main.android.dart create mode 100644 lib/ios/home.dart create mode 100644 lib/ios/main.dart diff --git a/lib/android/main.android.dart b/lib/android/main.android.dart new file mode 100644 index 0000000..a83e077 --- /dev/null +++ b/lib/android/main.android.dart @@ -0,0 +1,107 @@ +import 'package:flutter/material.dart'; + +class AndroidApp extends StatelessWidget { + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return new MaterialApp( + title: 'Flutter Demo', + theme: new ThemeData( + // This is the theme of your application. + // + // Try running your application with "flutter run". You'll see the + // application has a blue toolbar. Then, without quitting the app, try + // changing the primarySwatch below to Colors.green and then invoke + // "hot reload" (press "r" in the console where you ran "flutter run", + // or press Run > Flutter Hot Reload in IntelliJ). Notice that the + // counter didn't reset back to zero; the application is not restarted. + primarySwatch: Colors.blue, + ), + home: new AndroidHomePage(title: 'Flutter Demo Home Page'), + ); + } +} + +class AndroidHomePage extends StatefulWidget { + AndroidHomePage({Key key, this.title}) : super(key: key); + + // This widget is the home page of your application. It is stateful, meaning + // that it has a State object (defined below) that contains fields that affect + // how it looks. + + // This class is the configuration for the state. It holds the values (in this + // case the title) provided by the parent (in this case the App widget) and + // used by the build method of the State. Fields in a Widget subclass are + // always marked "final". + + final String title; + + @override + _AndroidHomePageState createState() => new _AndroidHomePageState(); +} + +class _AndroidHomePageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + // This call to setState tells the Flutter framework that something has + // changed in this State, which causes it to rerun the build method below + // so that the display can reflect the updated values. If we changed + // _counter without calling setState(), then the build method would not be + // called again, and so nothing would appear to happen. + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + // This method is rerun every time setState is called, for instance as done + // by the _incrementCounter method above. + // + // The Flutter framework has been optimized to make rerunning build methods + // fast, so that you can just rebuild anything that needs updating rather + // than having to individually change instances of widgets. + return new Scaffold( + appBar: new AppBar( + // Here we take the value from the MyHomePage object that was created by + // the App.build method, and use it to set our appbar title. + title: new Text(widget.title), + ), + body: new Center( + // Center is a layout widget. It takes a single child and positions it + // in the middle of the parent. + child: new Column( + // Column is also layout widget. It takes a list of children and + // arranges them vertically. By default, it sizes itself to fit its + // children horizontally, and tries to be as tall as its parent. + // + // Invoke "debug paint" (press "p" in the console where you ran + // "flutter run", or select "Toggle Debug Paint" from the Flutter tool + // window in IntelliJ) to see the wireframe for each widget. + // + // Column has various properties to control how it sizes itself and + // how it positions its children. Here we use mainAxisAlignment to + // center the children vertically; the main axis here is the vertical + // axis because Columns are vertical (the cross axis would be + // horizontal). + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Text( + 'You have pushed the button this many times:', + ), + new Text( + '$_counter', + style: Theme.of(context).textTheme.display1, + ), + ], + ), + ), + floatingActionButton: new FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: new Icon(Icons.add), + ), // This trailing comma makes auto-formatting nicer for build methods. + ); + } +} diff --git a/lib/ios/home.dart b/lib/ios/home.dart new file mode 100644 index 0000000..7d96381 --- /dev/null +++ b/lib/ios/home.dart @@ -0,0 +1,44 @@ +import 'package:flutter/cupertino.dart'; + +class IosHomeTab extends StatelessWidget { + @override + Widget build(BuildContext context) { + return new DefaultTextStyle( + style: const TextStyle( + fontFamily: '.SF UI Text', + inherit: false, + fontSize: 17.0, + color: CupertinoColors.black, + ), + child: new CupertinoPageScaffold( + child: new DecoratedBox( + decoration: const BoxDecoration(color: const Color(0xFFEFEFF4)), + child: new CustomScrollView( + slivers: [ + const CupertinoSliverNavigationBar( + largeTitle: const Text('Cupertino Refresh'), + ), + new CupertinoRefreshControl( + onRefresh: () { + // return new Future.delayed(const Duration(seconds: 2)) + // ..then((_) => setState(() => repopulateList())); + }, + ), + new SliverSafeArea( + top: false, // Top safe area is consumed by the navigation bar. + sliver: new SliverList( + delegate: new SliverChildBuilderDelegate( + (BuildContext context, int index) { + return new Text('abc'); + }, + childCount: 20, + ), + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/ios/main.dart b/lib/ios/main.dart new file mode 100644 index 0000000..a2d8f0d --- /dev/null +++ b/lib/ios/main.dart @@ -0,0 +1,86 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'home.dart'; + +class IosApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return new MaterialApp( + title: 'Flutter Demo', + theme: new ThemeData( + primarySwatch: Colors.blue, + ), + home: new IosHomePage(title: 'GitFlux'), + ); + } +} + +class IosHomePage extends StatefulWidget { + IosHomePage({Key key, this.title}) : super(key: key); + + final String title; + + @override + _IosHomePageState createState() => new _IosHomePageState(); +} + +class _IosHomePageState extends State { + // int _counter = 0; + + // void _incrementCounter() { + // setState(() { + // _counter++; + // }); + // } + + @override + Widget build(BuildContext context) { + return new CupertinoPageScaffold( + navigationBar: new CupertinoNavigationBar( + middle: new Text(widget.title), + ), + child: new CupertinoTabScaffold( + tabBar: new CupertinoTabBar( + items: const [ + const BottomNavigationBarItem( + icon: const Icon(CupertinoIcons.home), + title: const Text('Home'), + ), + const BottomNavigationBarItem( + icon: const Icon(CupertinoIcons.conversation_bubble), + title: const Text('Notification'), + ), + const BottomNavigationBarItem( + icon: const Icon(CupertinoIcons.profile_circled), + title: const Text('Profile'), + ), + ], + ), + tabBuilder: (BuildContext context, int index) { + return new DefaultTextStyle( + style: const TextStyle( + fontFamily: '.SF UI Text', + fontSize: 17.0, + color: CupertinoColors.black, + ), + child: new CupertinoTabView( + builder: (BuildContext context) { + switch (index) { + case 0: + return new IosHomeTab(); + break; + case 1: + return new IosHomeTab(); + break; + case 2: + return new IosHomeTab(); + break; + default: + } + }, + ), + ); + }), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index 94b23e9..a07e3c5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,109 +1,5 @@ import 'package:flutter/material.dart'; +// import 'main.android.dart'; +import 'ios/main.dart'; -void main() => runApp(new MyApp()); - -class MyApp extends StatelessWidget { - // This widget is the root of your application. - @override - Widget build(BuildContext context) { - return new MaterialApp( - title: 'Flutter Demo', - theme: new ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or press Run > Flutter Hot Reload in IntelliJ). Notice that the - // counter didn't reset back to zero; the application is not restarted. - primarySwatch: Colors.blue, - ), - home: new MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - _MyHomePageState createState() => new _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return new Scaffold( - appBar: new AppBar( - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: new Text(widget.title), - ), - body: new Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: new Column( - // Column is also layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug paint" (press "p" in the console where you ran - // "flutter run", or select "Toggle Debug Paint" from the Flutter tool - // window in IntelliJ) to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text( - 'You have pushed the button this many times:', - ), - new Text( - '$_counter', - style: Theme.of(context).textTheme.display1, - ), - ], - ), - ), - floatingActionButton: new FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: new Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); - } -} +void main() => runApp(new IosApp());