You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.5 KiB
196 lines
6.5 KiB
3 years ago
|
import 'dart:convert';
|
||
|
import 'dart:typed_data';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:provider/provider.dart';
|
||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
import 'package:teso/Classes/Uploading.dart';
|
||
|
import 'package:teso/providers/user_provider.dart';
|
||
|
import 'package:teso/util/consts.dart';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
|
||
|
class SubmitAdvert extends StatefulWidget {
|
||
|
final String video;
|
||
|
final String aspectRatio;
|
||
|
final Uint8List thumbnail;
|
||
|
final String campaignID;
|
||
|
|
||
|
const SubmitAdvert(
|
||
|
{Key key, this.video, this.aspectRatio, this.thumbnail, this.campaignID})
|
||
|
: super(key: key);
|
||
|
@override
|
||
|
_SubmitAdvertState createState() => _SubmitAdvertState();
|
||
|
}
|
||
|
|
||
|
class _SubmitAdvertState extends State<SubmitAdvert> {
|
||
|
TextEditingController controller;
|
||
|
SharedPreferences prefs;
|
||
|
bool sending = false;
|
||
|
|
||
|
void postVideo(context) async {
|
||
|
setState(() {
|
||
|
sending = true;
|
||
|
});
|
||
|
try {
|
||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
|
String token = prefs.getString("tokensTeso");
|
||
|
Map<String, String> requestHeaders = {'Authorization': token};
|
||
|
String urlLocation = tesoStreaming + "api/mobile/upload/authurl";
|
||
|
var client =
|
||
|
await http.get(Uri.parse(urlLocation), headers: requestHeaders);
|
||
|
if (client.statusCode == 200) {
|
||
|
var details = jsonDecode(client.body);
|
||
|
String muxuploadsID = details["data"]["id"];
|
||
|
String muxuploadsURL = details["data"]["url"];
|
||
|
|
||
|
Provider.of<UserProvider>(context, listen: false).uploadPost(Uploading(
|
||
|
id: DateTime.now().toString() +
|
||
|
widget.video.replaceAll("file://", ""),
|
||
|
aspect: widget.aspectRatio,
|
||
|
path: widget.video.replaceAll("file://", ""),
|
||
|
thumbnail:
|
||
|
widget.thumbnail != null ? base64Encode(widget.thumbnail) : null,
|
||
|
title: controller.text,
|
||
|
pending: 0,
|
||
|
campaignID: widget.campaignID,
|
||
|
muxuploadID: muxuploadsID,
|
||
|
muxuploadURL: muxuploadsURL,
|
||
|
));
|
||
|
Navigator.pop(context);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
print("Something is " + e.toString());
|
||
|
}
|
||
|
setState(() {
|
||
|
sending = false;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
controller = new TextEditingController();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
|
super.dispose();
|
||
|
controller.dispose();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: PreferredSize(
|
||
|
child: AppBar(
|
||
|
automaticallyImplyLeading: true,
|
||
|
title: Text("Post"),
|
||
|
centerTitle: true,
|
||
|
),
|
||
|
preferredSize: Size.fromHeight(70.0),
|
||
|
),
|
||
|
body: SingleChildScrollView(
|
||
|
child: Container(
|
||
|
width: MediaQuery.of(context).size.width,
|
||
|
height: MediaQuery.of(context).size.height,
|
||
|
padding: EdgeInsets.all(MediaQuery.of(context).size.width * 0.025),
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Container(
|
||
|
width: MediaQuery.of(context).size.width,
|
||
|
child: Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
children: [
|
||
|
Container(
|
||
|
width: MediaQuery.of(context).size.width * 0.25,
|
||
|
height: MediaQuery.of(context).size.width * 0.35,
|
||
|
color: Colors.black,
|
||
|
child: widget.thumbnail != null
|
||
|
? Image.memory(widget.thumbnail)
|
||
|
: CupertinoActivityIndicator(
|
||
|
animating: true,
|
||
|
radius: 15,
|
||
|
),
|
||
|
),
|
||
|
Container(
|
||
|
width: (MediaQuery.of(context).size.width) -
|
||
|
(MediaQuery.of(context).size.width * 0.35),
|
||
|
height: MediaQuery.of(context).size.width * 0.35,
|
||
|
child: TextField(
|
||
|
decoration: InputDecoration(
|
||
|
border: OutlineInputBorder(
|
||
|
borderSide: BorderSide.none,
|
||
|
),
|
||
|
filled: true,
|
||
|
isDense: true,
|
||
|
labelText: "Say Something..",
|
||
|
labelStyle: TextStyle(
|
||
|
color: Colors.black54,
|
||
|
),
|
||
|
fillColor: Colors.white70,
|
||
|
),
|
||
|
controller: controller,
|
||
|
maxLines: null,
|
||
|
keyboardType: TextInputType.url,
|
||
|
textInputAction: TextInputAction.done,
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height: 20,
|
||
|
),
|
||
|
Divider(),
|
||
|
Container(
|
||
|
margin: EdgeInsets.only(
|
||
|
top: 10,
|
||
|
),
|
||
|
child: Text(
|
||
|
"Teso businesses and other Teso users can only see campaign post on your profile after they have been approved by the campaign owners.",
|
||
|
textAlign: TextAlign.center,
|
||
|
style: TextStyle(
|
||
|
color: Colors.grey,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
floatingActionButton: !sending
|
||
|
? Container(
|
||
|
margin: EdgeInsets.all(20),
|
||
|
width: MediaQuery.of(context).size.width,
|
||
|
decoration: BoxDecoration(
|
||
|
borderRadius: BorderRadius.circular(15.0),
|
||
|
color: tesoBlue,
|
||
|
),
|
||
|
child: InkWell(
|
||
|
onTap: () => postVideo(context),
|
||
|
child: Center(
|
||
|
child: Text(
|
||
|
"NEXT",
|
||
|
style: TextStyle(
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
height: 50,
|
||
|
)
|
||
|
: Container(
|
||
|
width: MediaQuery.of(context).size.width,
|
||
|
height: 50,
|
||
|
child: Center(
|
||
|
child: CupertinoActivityIndicator(
|
||
|
animating: true,
|
||
|
radius: 15,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||
|
);
|
||
|
}
|
||
|
}
|