Created
September 29, 2019 12:27
-
-
Save zhuharev/685abd0bcf04ebab8f1a0eb95a4d89a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:io'; | |
import 'package:flutter/material.dart'; | |
import 'package:sliding_up_panel/sliding_up_panel.dart'; | |
import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
import 'package:http/http.dart' as http; | |
import 'package:json_annotation/json_annotation.dart'; | |
import 'package:bloc/bloc.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import '../feed/feed_page.dart'; | |
import '../feed/feed_bloc.dart'; | |
part 'trash.g.dart'; | |
@JsonSerializable() | |
class Offer { | |
int id; | |
int price; | |
Offer(this.id,this.price); | |
factory Offer.fromJson(Map<String, dynamic> json) => _$OfferFromJson(json); | |
} | |
@JsonSerializable() | |
class OffersResponse { | |
final List<Offer> offers; | |
OffersResponse(this.offers); | |
factory OffersResponse.fromJson(Map<String, dynamic> json) => _$OffersResponseFromJson(json); | |
} | |
class RPCResponse { | |
Map<String, dynamic> result; | |
RPCResponse(this.result); | |
RPCResponse.fromJson(Map<String, dynamic> json) : result = json['result']; | |
} | |
class MyApp extends StatefulWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
} | |
// state | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | |
final List<Tab> myTabs = <Tab>[ | |
Tab(icon: Icon(Icons.directions_car)), | |
Tab(icon: Icon(Icons.directions_transit)), | |
Tab(icon: Icon(Icons.directions_bike)), | |
Tab(icon: Icon(Icons.directions_bike)), | |
Tab(icon: Icon(Icons.directions_bike)), | |
]; | |
var _appBar; | |
bool _isShowTabs = false; | |
var physics = NeverScrollableScrollPhysics(); | |
int _tabIndex = 0; | |
TabController _tabController; | |
void _secondTab() { | |
setState(() { | |
_tabController.animateTo(1); | |
}); | |
} | |
static Future<void> _makeHTTPRequest() async{ | |
var url = 'https://m.ugnest.com/rpc/v1'; | |
var body = jsonEncode({'id': 1, 'method': 'offers.fastcards','jsonrpc':'2.0'}); | |
var response = await http.post(url, body: body, headers: {"Content-Type": "application/json"}); | |
RPCResponse resp = RPCResponse.fromJson(jsonDecode(response.body)); | |
OffersResponse offers = OffersResponse.fromJson(resp.result); | |
print('Response status: ${offers.offers[0].id}'); | |
print('Response body: ${response.body}'); | |
} | |
void _toggleTabs() { | |
setState(() { | |
_isShowTabs = !_isShowTabs; | |
}); | |
} | |
void _handleTabChange() { | |
setState(() { | |
_tabIndex = _tabController.index; | |
if (!_tabController.indexIsChanging) { | |
if (_tabIndex == 0) { | |
_isShowTabs = false; | |
} else { | |
_isShowTabs = true; | |
} | |
} | |
}); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
_tabController = TabController(vsync: this, length: myTabs.length); | |
_tabController.addListener(_handleTabChange); | |
_appBar = new PreferredSize( | |
preferredSize: Size.fromHeight(kToolbarHeight), | |
child: new Container( | |
color: Colors.green, | |
child: new SafeArea( | |
child: Column( | |
children: <Widget>[ | |
new Expanded(child: new Container()), | |
new TabBar( | |
tabs: myTabs, | |
controller: _tabController, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
@override | |
void dispose() { | |
_tabController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
BorderRadiusGeometry radius = BorderRadius.only( | |
topLeft: Radius.circular(24.0), | |
topRight: Radius.circular(24.0), | |
); | |
return MaterialApp( | |
title:'sds', | |
home: DefaultTabController( | |
length: 5, | |
child: Scaffold( | |
appBar: _isShowTabs?_appBar:null, | |
body: TabBarView( | |
controller: _tabController, | |
physics: _isShowTabs?null:physics, | |
children: [ | |
SlidingUpPanel( | |
panel: GestureDetector( | |
onPanUpdate: (details) { | |
if (details.delta.dx < 0) { | |
// swiping in right direction | |
_secondTab(); | |
} | |
}, | |
child: Container( | |
color: Colors.white, | |
margin: const EdgeInsets.only(top: 20.0), | |
child: Row( | |
children: <Widget>[ | |
Column( | |
children: <Widget>[ | |
RaisedButton(child: Text("Rock & Roll"), | |
onPressed: _makeHTTPRequest, | |
color: Colors.red, | |
textColor: Colors.yellow, | |
padding: EdgeInsets.fromLTRB(10, 10, 10, 10), | |
splashColor: Colors.grey, | |
) | |
], | |
) | |
], | |
), | |
) | |
) , | |
body: MapSample(), | |
borderRadius: radius, | |
), | |
Row(children: <Widget>[ | |
Column(children: <Widget>[ | |
RaisedButton(child: Text("Rock & Roll"), | |
onPressed: _toggleTabs, | |
color: Colors.red, | |
textColor: Colors.yellow, | |
padding: EdgeInsets.fromLTRB(10, 10, 10, 10), | |
splashColor: Colors.grey, | |
) | |
]) | |
]), | |
BlocProvider<CounterBloc>( | |
builder: (context) => CounterBloc(), | |
child: CounterPage(), | |
), | |
Text('$_tabIndex'), | |
Icon(Icons.directions_bike), | |
], | |
), | |
), | |
) | |
); | |
} | |
} | |
class MapSample extends StatefulWidget { | |
@override | |
State<MapSample> createState() => MapSampleState(); | |
} | |
class MapSampleState extends State<MapSample> { | |
Completer<GoogleMapController> _controller = Completer(); | |
static final CameraPosition _kGooglePlex = CameraPosition( | |
target: LatLng(37.42796133580664, -122.085749655962), | |
zoom: 14.4746, | |
); | |
static final CameraPosition _kLake = CameraPosition( | |
bearing: 192.8334901395799, | |
target: LatLng(37.43296265331129, -122.08832357078792), | |
tilt: 59.440717697143555, | |
zoom: 19.151926040649414); | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
body: GoogleMap( | |
mapType: MapType.normal, | |
initialCameraPosition: _kGooglePlex, | |
onMapCreated: (GoogleMapController controller) { | |
_controller.complete(controller); | |
}, | |
), | |
floatingActionButton: FloatingActionButton.extended( | |
onPressed: _goToTheLake, | |
label: Text('To the lake!'), | |
icon: Icon(Icons.directions_boat), | |
), | |
); | |
} | |
Future<void> _goToTheLake() async { | |
final GoogleMapController controller = await _controller.future; | |
controller.animateCamera(CameraUpdate.newCameraPosition(_kLake)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment