Вы должны использовать appBar: AppBar(...
внутри своей эшафот. Поэтому MaterialApp-> Scaffold -> (AppBar и listview).
Пример кода:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("This is the title"),
),
body: ListView(
children: <Widget>[
Text("This is text 1"),
Text("This is text 2"),
Text("This is text 3"),
Text("This is text 4"),
Text("This is text 5"),
Text("This is text 6"),
Text("This is text 7"),
Text("This is text 8"),
Text("This is text 9"),
Text("This is text 10"),
Text("This is text 11"),
Text("This is text 12"),
Text("This is text 13"),
Text("This is text 14"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
],
),
),
);
}
}
Элементы радио-или флажка непроверенные не отправлены, поскольку их не рассматривают как успешных. Таким образом, необходимо проверить, отправляются ли они с помощью isset
или empty
функция.
if (isset($_POST['checkbox'])) {
// checkbox has been checked
}
Я время от времени использовал эту технику:
<input type="hidden" name="the_checkbox" value="0" />
<input type="checkbox" name="the_checkbox" value="1" />
примечание: Это становится интерпретируемым по-другому на различных языках серверной стороны, так протестируйте и корректируйтесь при необходимости. Благодаря SimonSimCity для подсказки.
Для добавления к коду fmsf при добавлении флажков, я делаю их массивом при наличии [] на имя
<FORM METHOD=POST ACTION="statistics.jsp?q=1&g=1">
<input type="radio" name="gerais_radio" value="primeiras">Primeiras Consultas por medico<br/>
<input type="radio" name="gerais_radio" value="salas">Consultas por Sala <br/>
<input type="radio" name="gerais_radio" value="assistencia">Pacientes por assistencia<br/>
<input type="checkbox" name="option[]" value="Option1">Option1<br/>
<input type="checkbox" name="option[]" value="Option2">Option2<br/>
<input type="checkbox" name="option[]" value="Option3">Option3<br/>
<input type="submit" value="Ver">
Флажок непроверенный не становится отправленным в данных POST. Необходимо просто проверить, пусто ли это:
if (empty($_POST['myCheckbox']))
....
else
....
Используйте это
$myvalue = (isset($_POST['checkbox']) ? $_POST['checkbox'] : 0;
Или занимая место независимо от того, что Ваше никакое значение не для 0
Вот простой обходной путь с использованием javascript:
перед отправкой формы, содержащей флажки, установите для «выключенных» значение 0 и проверьте их, чтобы убедиться, что они отправлены. это работает, например, для массивов флажков.
///// пример //////
для формы с id = "formId"
<form id="formId" onSubmit="return formSubmit('formId');" method="POST" action="yourAction.php">
<!-- your checkboxes here . for example: -->
<input type="checkbox" name="cb[]" value="1" >R
<input type="checkbox" name="cb[]" value="1" >G
<input type="checkbox" name="cb[]" value="1" >B
</form>
<?php
if($_POST['cb'][$i] == 0) {
// empty
} elseif ($_POST['cb'][$i] == 1) {
// checked
} else {
// ????
}
?>
<script>
function formSubmit(formId){
var theForm = document.getElementById(formId); // get the form
var cb = theForm.getElementsByTagName('input'); // get the inputs
for(var i=0;i<cb.length;i++){
if(cb[i].type=='checkbox' && !cb[i].checked) // if this is an unchecked checkbox
{
cb[i].value = 0; // set the value to "off"
cb[i].checked = true; // make sure it submits
}
}
return true;
}
</script>